简体   繁体   English

如何实现瞬态Actor失败的重试?

[英]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? 使用主管我可以让actor重新启动,这是尝试重置为工作状态的理想选择,但是如何在失败时重试它正在处理的消息?

Thanks! 谢谢!

You need to implement the Command pattern. 您需要实现Command模式。 A Command is an object that encapsulates an operation to be performed, along with its arguments, and exists independent of the Actor. Command是一个对象,它封装了要执行的操作及其参数,并且独立于Actor存在。 If the Actor fails in a fashion that is retryable, the supervisor resubmits the Command to the Actor. 如果Actor以可重试的方式失败,则主管将Command重新提交给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. 如果Actor被提供流并处理消息,则Actor必须填充命令列表并记录完成,以便它可以在正确的位置重新启动。 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. 如果流不可重绕,则必须在启动之前排队所有命令,并且Actor必须在每个Command上记录完成状态,因此可以在瞬时失败时重新提交链。

The Command pattern can also be used to implement history and undo. Command模式还可用于实现历史记录和撤消。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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