简体   繁体   English

Akka 演员监督 - “恢复”是否保留当前消息?

[英]Akka Actors Supervision - Does 'resume' keep current message?

In Akka Actors (using Scala) one can use supervison strategies to deal with exceptions.在 Akka Actors(使用 Scala)中,可以使用监督策略来处理异常。 This strategy can decide what to do with the actor, depending on the type of exception.这个策略可以根据异常的类型来决定对actor做什么。 From my understanding, there are 4 possibilible outcomes:根据我的理解,有4种可能的结果:

  • Resume - Let the child actor keep its current state and continue processing new messages like nothing happened. Resume - 让子 Actor 保留其当前的 state 并继续处理新消息,就像什么都没发生一样。
  • Restart - Restart the child actor ie kill the current child actor that failed and create a new one in its place. Restart - 重新启动子actor,即杀死当前失败的子actor并在其位置创建一个新子actor。
  • Stop - Shut down the child actor permanently.停止- 永久关闭子演员。
  • Escalate - Let the supervisor's supervisor handle this error.升级- 让主管的主管处理此错误。

The documentation clearly states that upon restarting an actor, the current message will be lost and this has to be dealt with. 文档清楚地指出,在重新启动参与者时,当前消息将丢失,必须进行处理。 However, it does not clearly mention if the same applies to resume.但是,它没有明确提及是否同样适用于简历。 Does it continue handling that messages (assuming some external factor caused the exception which isn't there anymore), or does it continue with the next message in the mailbox?它是否继续处理该消息(假设某些外部因素导致不再存在的异常),还是继续处理邮箱中的下一条消息?

Does 'resume' keep current message? “恢复”是否保留当前消息?

No.不。

The "what happens to the message" section of the documentation describes the behavior when an exception is thrown while an actor is processing a message:文档的“消息发生了什么”部分描述了当参与者处理消息时抛出异常时的行为:

What happens to the message消息会发生什么

If an exception is thrown while a message is being processed (ie taken out of its mailbox and handed over to the current behavior), then this message will be lost.如果在处理消息时抛出异常(即从其邮箱中取出并交给当前行为),则该消息将丢失。 It is important to understand that it is not put back on the mailbox.重要的是要了解它不会放回邮箱。 So if you want to retry processing of a message, you need to deal with it yourself by catching the exception and retry your flow.因此,如果您想重试处理一条消息,您需要自己处理它,通过捕获异常并重试您的流程。 Make sure that you put a bound on the number of retries since you don't want a system to livelock (so consuming a lot of cpu cycles without making progress).确保限制重试次数,因为您不希望系统活锁(因此消耗大量 cpu 周期而没有取得进展)。

The above behavior applies to any of the supervision strategies: resume, restart, or stop.上述行为适用于任何监督策略:恢复、重启或停止。 ("Escalate" is a fourth strategy in classic Akka but is not explicitly supported in Akka Typed . However, escalation can be emulated in Akka Typed .) (“升级”是经典 Akka 中的第四种策略,但在 Akka Typed 中没有明确支持。但是, 升级可以在 Akka Typed 中模拟。)

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

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