简体   繁体   中英

How to Implement Retry on Transient Actor Failure?

I'm in a typical situation where I have a group of worker actors that are being fed jobs from a queue. Worker failures can be either transient and due to the environment, or permanent and due to an invalid job.

Inside the worker actor I'm handling the permanent failure case, but how can I implement a retry for the transient cases? With a supervisor I can have the actor restarted, which is desirable to try and reset to a working state, but how then can I retry the message it was working on when it failed?

Thanks!

You need to implement the Command pattern. A Command is an object that encapsulates an operation to be performed, along with its arguments, and exists independent of the Actor. If the Actor fails in a fashion that is retryable, the supervisor resubmits the Command to the Actor. If the Actor is fed a stream and processes messages, then the Actor must populate a list of Commands and record completion so it can restart at the right place. If the stream isn't rewindable, then you have to queue up ALL the commands before starting, and the Actor must record completion status on each Command, so the chain can be resubmitted on transient failure.

The Command pattern can also be used to implement history and undo.

如果您正在使用Akka 1.2或master,则可以覆盖preRestart以获取演员崩溃时当前的消息。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM