0
我試圖在這裏提出儘可能簡單的變化的問題.. 我寫了一個單元測試,作爲代碼的副作用,創建一個單身演員。在他的preStart方法中,他通過調用startJobCoordinator方法創建其他單身演員。現在Akka單身男演員不接收消息
private boolean startJobCoordinator(JobConfiguration jobConfiguration) throws InterruptedException {
ActorRef jobRef = createSingletonActor(Props.create(JobCoordinator.class, jobConfiguration.getId()), jobConfiguration.getId());
jobRef.tell("DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD", self());
TimeUnit.SECONDS.sleep(1);
return true;
}
private ActorRef createSingletonActor(Props props, final String name) {
final ClusterSingletonManagerSettings settings = ClusterSingletonManagerSettings.create(getContext().system());
getContext().actorOf(ClusterSingletonManager.props(props, PoisonPill.getInstance(), settings), name);
ClusterSingletonProxySettings proxySettings = ClusterSingletonProxySettings.create(getContext().system());
return getContext().actorOf(ClusterSingletonProxy.props("/user" + name, proxySettings), name + "Proxy");
}
,所述JobCoordinator單演員其是類型AbstractActor的內部,我已經寫了接收方法如下:
match(String.class, System.err::println).build();
在單元測試中, 「DDDDDDDDDDDDDDDDDDDDD」消息沒有收到(並沒有打印)。
當作爲運行整個系統的一部分運行相同的代碼時,JobCoordinator參與者獲取消息。 當我創建JobCoordinator作爲普通的演員而不是單身人士時,他得到消息(甚至作爲單元測試的一部分)。
我真的很無助..任何幫助將不勝感激。
如果向我們顯示「JobCoordinator」,「ClusterSingletonManager」,「ClusterSingletonProxy」和「ClusterSingletonManagerSettings」的代碼,它將會很有用。設計中有許多層次的複雜性,使其難以遵循,因此可能值得回顧。 – nickebbitt
ClusterSingletonProxy,ClusterSingletonManager和ClusterSingletonManagerSettings都是akka類 只有作業協調員不是,我不確定我可以在這裏發佈代碼。 這個問題在某種程度上消失了,我不確定如何......如果我想出答案,我會更新以備將來參考。 –