1

I have a child "consumer" actor that connects to some external data stream, parses its messages and forwards them further inside the application. This "producer" system has a pub-sub architecture, but does not restore subscriptions after reconnect. Currently I store these subscriptions in parent actor and resend them in supervisor, but the problem is that while the child is restarting, they get forwarded to dead letter queue. I could have tried scheduling these to parent after some delay, but this may interfere with subscription order, which is important.

So how do I do deliver these "resubscription" messages to the child while it's restarting?

fghkngfdx
  • 135
  • 4
  • If it is of any importance, child is supervised by `BackoffSupervisor` with `Backoff.onFailure(...).withSupervisorStrategy(resubscribingStrategy)` – fghkngfdx Sep 13 '16 at 07:48

2 Answers2

1

You can use Restart Hooks (http://doc.akka.io/docs/akka/snapshot/scala/actors.html#Restart_Hooks): preRestart and postRestart api.

on preRestart on the child actor, you need to inform the supervisor that child actor will be restarting and supervisor should suspend it's sending of message.

on postRestart on the child actor, you need to inform the supervisor that child is available and supervisor should resume sending message.

  • Isn't there a race between child sending "I'm restarting" and the parent sending to the child? – tariksbl Sep 13 '16 at 14:26
  • Yes there is but it's a matter of implement the right protocol, parent shouldn't send a message to child if child haven't acknowledge yet that there previous message is already process. – Leo Bufi Barrameda Sep 15 '16 at 09:26
0

You can subscribe to dead letters with

context.system.eventStream.subscribe(myListenerActorRef, classOf[DeadLetter])
...
def receive = {
  case DeadLetter(msg, from, to) =>
  //Do my custom stuff here
}

, store and send them again.

dveim
  • 3,381
  • 2
  • 21
  • 31
  • But this will make me have two message "queues", potentially jeopardizing their order. Is there some way to schedule message on actor start, without trying to send it to the dying incarnation and trying to reprocess its rejections? – fghkngfdx Sep 13 '16 at 08:01
  • Possible hack -- introduce `listensDeadletters / listensRegular` state in restarting actor. However, better solution is to have pool of actors, so restarting one of them wont be harmful. – dveim Sep 13 '16 at 09:09