Creating Reactive Services using Servicestack and Server Events

I am trying to create reactive Service using Servicestack and Serversent Events. The thing I was doing is I post message to service. And directly push that message to actor. That is post only non blocking agent. Currently I am using F# actor but can be AKKA or any other. And then return accepted status code.

And from that I wanted to push processed message to Server Events. That eventually reach client in pushed fashion. I was trying to use Chat demo as reference but couldn’t quite make it work the server event part.

So, here are the queries

  • Am I on a right path to create reactive services?
  • Is there any good reference I can user other than chat or any suggestion to complete this reactive circle?

Let me know if anything is not clear or required more details.

Not sure I see why it needs to go through Server Events? SSE is essentially for providing server push events over HTTP.

I’d personally take the most direct possible, i.e. is there a reason why you can’t call the F#/Akka service directly? or whether the F#/Akka library can’t call ServiceStack services directly?

No, I can call. But the thing I wanted to achieve is user should not wait for processed message. And if connection is open for user it will receive pushed event from server whenever data is ready. I don’t want to block user for reply. So, I feel like SSE would be better option. Just create something like https://reactivetrader.azurewebsites.net/. It is created with SingleR, AFAIK and I was trying to do with SSE.

I’d need to see a concrete example, but I wouldn’t think SSE is the optimal choice for server side communication.

You can just use the async API’s to avoid blocking.

@mythz Hi, I just made it work. Details are here http://kunjan.in/2015/11/reactive-services-with-servicestack-and-fsharp/ . Do have a look. Will love to know and other servicestack user’s view on this one.

Cool, FYI a short-hand for resolving a dependency is HostContext.Resolve<IServerEvents>() seems you could avoid the SSE module completely with just:

HostContext.Resolve<IServerEvents>().NotifyAll({HelloResponse.Result = reversed})

Also never used AKKA before, but where is AKKA being used in this example?

@mythz AKKA is not being used. I am using more traditional / conventional actor. Basic one that is in built language feature of F#.

I m planning big Servicestack + AKKA blog for https://sergeytihon.wordpress.com/2015/10/25/f-advent-calendar-in-english-2015/.

Thanks for short hand. I ll update the code tomorrow. But for second part NotifyAll(Object) is extension method that I can’t use without using open Servicestack and I was facing issue with async keyword. So, just to make it work I wrap it with module.

1 Like