Sim*_*mon 11
我在B中所做的是在preRestart中再次向B发送消息,请参阅下面的代码.
@Override
public void preRestart(final Throwable reason, final scala.Option<Object> message) throws Exception
{
getSelf().tell(message.get(), getSender());
};
Run Code Online (Sandbox Code Playgroud)
为了确保我不以无限循环结束,我在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();
}
});
Run Code Online (Sandbox Code Playgroud)
这应该是保证,有问题的信息只会重发三次.如果这是一个好的做法或者让我联系到更好的解决方案,有人可以给我一个建议吗?
| 归档时间: |
|
| 查看次数: |
1349 次 |
| 最近记录: |