These are chat archives for petabridge/akka-bootcamp

24th
Mar 2015
Bobby
@bobbychopra
Mar 24 2015 00:25
Any thoughts on the following: I have a piece of code that subscribes to a messaging service eg. TibcoRV. Since it is always handling messages received on the topic, can I even make something like this an Actor? Or would it have to live outside the ActorSystem?
Would be nice to make it an actor, in case something happened to the messaging service, I would get the Supervisor to retry/restart the child actor
Arjen Smits
@Danthar
Mar 24 2015 07:04
Sure you can
Arjen Smits
@Danthar
Mar 24 2015 07:11
Not sure how your subscription code for TibcoRV works, but if it dispatches each recieved message on a seperate Task/Thread you have to make sure to marshal the result (e.g your message) back to the thread the Actor runs on. Else you risk breaking the Actor model. And ofcourse always transform your results into messages for your actor system. There is a nice example on how to do that, should you need to, in the Akka bootcamp lesson 3.4 with the PipeTo method.
Bobby
@bobbychopra
Mar 24 2015 11:28
My understanding is PipeTo is useful when you initiate the Task. In the case of a messaging service, you pass in a callback handler. I could have the callback handler just Tell the message to an actor
However, I would like the code that Subscribes/Unsubscribes to the messaging service be an actor, so that it can be restarted (by a supervising actor) in the event of an exception. Does that help?
Arjen Smits
@Danthar
Mar 24 2015 11:33
well in regards to managing your subscription. Certainly using an Actor for that would work fine.
However im not sure if it matters that the callback is executed on the same context as the Actor is running on. Some messaging client execute the callback on a seperate thread, and others marshall it back to the original context.
But i suppose you could just close over the ActorRef your Tell-ing your message to. And that should work as well.
So something like this:
Receive<StartSubscription>(_ => {

subscription = myMessageClient.Subscribe<myMessage>(m => {

    workerActorRef.Tell(new JuleeDoTheThing() { ... })

});

});
Arjen Smits
@Danthar
Mar 24 2015 11:38
and markdown is not my friend atm. But you get what i mean
Arjen Smits
@Danthar
Mar 24 2015 11:46
Im currently doing something similar myself btw
only then im using a RabbitMq client
I don't have it wrapped up inside an Actor though. Since receiving a message from the client is the starting point of my Actor processing line. It seemed redundant having a separate actor for that. Also auto-reconnect and such is handled for me by the RabbitMq client.
Arjen Smits
@Danthar
Mar 24 2015 14:41
If I have an Actor that has multiple different typed childActors. Can I have a different supervision strategy for each of them?