Akka升级监督策略制止儿童

编程入门 行业动态 更新时间:2024-10-26 02:26:26
本文介绍了Akka升级监督策略制止儿童的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试OneForOneStrategy策略,该策略升级失败.我的Actor结构是:Supervisor -> Slave,其中Slave是Supervisor的子代.

从站响应2条消息-"失败"(引发异常)和"工作"(进行一些记录)

我的第一个问题是,如果Slave失败,则Supervisor将重新启动(由于升级策略,"Guardian"已将其重新启动),但是Slave已停止且未重新启动.

我猜想这种默认行为是有原因的,即停止子进程而不是重新启动子进程.您能解释一下这个设计决定吗?在什么情况下,这比重新启动更好?

我的行为问题是从站的收件箱看起来像这样:"工作","失败","工作".

失败后,由于从站已停止&;最后一条工作"消息以死信"结尾.已启动(通过Supervisor的初始化). 解决方案是覆盖preRestart方法:

@Override public void preRestart(Throwable reason, Optional<Object> message) throws Exception { postStop(); }

这解决了问题,并导致子级重新启动.我还必须在Supervisor中更改Slave的初始化.

解决方案

子级被停止的原因是,它们被视为actor内部状态的一部分,并且当actor重新启动时,它将从其启动可以这么说.

您已经注意到,可以通过覆盖preRestart选择退出.

我们正在重新研究Akka Typed(这是下一代Akka actor API)的默认行为,如果您好奇的话,可以在这里看到一些讨论: github/akka/akka/issues/25556

I'm experimenting with OneForOneStrategy strategy, which escalates the failure. My structure of Actor is: Supervisor -> Slave, where Slave is child of Supervisor.

Slave responds to 2 messages - "fail" (throws exception) and "work" (makes some logging)

My first problem was that if Slave failed, then Supervisor got restarted (because of the escalation strategy, the "Guardian" have restarted it), however Slave was stopped and not restarted.

I guess there is a reason to this default behavior of stopping the children instead of restarting them. Could you please explain this design decision? In which cases is this a better approach than restart ?

My problem with the behavior was that Slave's inbox looked like this: "work", "fail", "work".

After the failure, the last "work" message ended in Dead Letter, since the Slave was stopped & started (by initialization of Supervisor). The solution was to override the preRestart method:

@Override public void preRestart(Throwable reason, Optional<Object> message) throws Exception { postStop(); }

This fixed the problem and caused the children to be restarted. I also had to change the initialization of Slave in Supervisor.

解决方案

The reason the children are stopped is that they are seen as part of the internal state of the actor, and when an actor is restarted it is to start it from a clean slate so to speak.

As you have noted you can opt out of it by overriding preRestart.

We are revisiting this default behavior for Akka Typed, which is the next generation of the Akka actor API, you can see some discussion here if you are curious: github/akka/akka/issues/25556

更多推荐

Akka升级监督策略制止儿童

本文发布于:2023-11-25 15:58:13,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1630394.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:策略   儿童   Akka

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!