2015-05-01 43 views

回答

10

我在B中所做的是在preRestart中再次將消息發送給B,請參閱下面的代碼。

@Override 
    public void preRestart(final Throwable reason, final scala.Option<Object> message) throws Exception 
    { 
    getSelf().tell(message.get(), getSender()); 
    }; 

爲了確保我不會死循環結束,我配置一個主管策略如下:

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(); 
    } 
    });  

這應該gurarantee,有問題的消息是隻有三個重發時間。如果這是一種好的做法,或者可以將我與更好的解決方案聯繫起來,有人能給我一個建議嗎

+0

人們告訴他們罰款:http://stackoverflow.com/questions/13542921/akka-resending-the-breaking-message – invis

相關問題