如何在主管策略重启演员后重新发送消息
Howto resend message after actor is restarted by supervisor strategy
我有父演员 (A) 和两个子演员 (B)。
我在A做了supervisor策略,所以如果B发生特定的异常,B会重启。
如何将导致B异常的消息重新发送给B?
我在B中所做的就是在preRestart中再次向B发送消息,见下面的代码。
@Override
public void preRestart(final Throwable reason, final scala.Option<Object> message) throws Exception
{
getSelf().tell(message.get(), getSender());
};
为了确保我不会死循环,我在 A 中配置监督策略如下:
private final SupervisorStrategy strategy = new OneForOneStrategy(3, Duration.Inf(),
new Function<Throwable, SupervisorStrategy.Directive>()
{
@Override
public Directive apply(final Throwable t) throws Exception
{
if (t instanceof SpecificException)
{
return SupervisorStrategy.restart();
}
return SupervisorStrategy.escalate();
}
});
这应该保证,有问题的消息只被重发了 3 次。如果这是好的做法或者 link 我有更好的解决方案,有人可以给我建议吗?
我有父演员 (A) 和两个子演员 (B)。 我在A做了supervisor策略,所以如果B发生特定的异常,B会重启。
如何将导致B异常的消息重新发送给B?
我在B中所做的就是在preRestart中再次向B发送消息,见下面的代码。
@Override
public void preRestart(final Throwable reason, final scala.Option<Object> message) throws Exception
{
getSelf().tell(message.get(), getSender());
};
为了确保我不会死循环,我在 A 中配置监督策略如下:
private final SupervisorStrategy strategy = new OneForOneStrategy(3, Duration.Inf(),
new Function<Throwable, SupervisorStrategy.Directive>()
{
@Override
public Directive apply(final Throwable t) throws Exception
{
if (t instanceof SpecificException)
{
return SupervisorStrategy.restart();
}
return SupervisorStrategy.escalate();
}
});
这应该保证,有问题的消息只被重发了 3 次。如果这是好的做法或者 link 我有更好的解决方案,有人可以给我建议吗?