Akka:如何重新连接到重新启动的从属服务器?

Akka:如何重新连接到重新启动的从属服务器?,akka,Akka,我有两个docker容器在本地运行,一个是主容器,第二个是从容器,通过akka remote进行通信。对于某些消息,从站可以不时发出OOM,在这种情况下,docker会优雅地重新启动它 代码看起来有点像这样: object Master { def main() { ... val slave = typedActorOf(TypedProps[Slave], resolveRemoteAtor(..)) val dispatcher =

我有两个docker容器在本地运行,一个是主容器,第二个是从容器,通过akka remote进行通信。对于某些消息,从站可以不时发出OOM,在这种情况下,docker会优雅地重新启动它

代码看起来有点像这样:

object Master {

  def main() {
    ...
    val slave = 
      typedActorOf(TypedProps[Slave], resolveRemoteAtor(..))
    val dispatcher = 
      typedActorOf(TypedProps(classOf[Dispatcher], new DispatcherImpl(slave)))
    val httpServer = 
      typedActorOf(TypedProps(classOf[HTTPServer], new HTTPServerImpl(dispatcher)))
  }
}

class Slave() { def compute() = ... }

class Dispatcher(s: Slave) { def compute() = s.compute() }
问题是,一旦从机由于OOM而变得不可用,主机就会关闭与从机的连接,并且它永远不会更新该连接:

[ERROR] from a.r.EndpointWriter - AssociationError akka.tcp://MasterSystem@localhost:0] -> [akka.tcp://SlaveSystem@localhost:1]: Error [Shut down address: akka.tcp://SlaveSystem@localhost:1] [akka.remote.ShutDownAssociation: Shut down address: akka.tcp://SlaveSystem@localhost:1 Caused by: akka.remote.transport.Transport$InvalidAssociationException: The remote system terminated the association because it is shutting down. ]
[INFO]  from a.r.RemoteActorRef - Message [akka.actor.TypedActor$MethodCall] from Actor[akka://MasterSystem/temp/$c] to Actor[akka.tcp://SlaveSystem@localhost:1/user/Slave#1817887555] was not delivered. [1] dead letters encountered.

因此,我的问题是,在从机重新启动后,如何强制主机重新连接从机,并发送所有在其关闭期间无法发送的挂起消息?

我建议直接使用Akka Cluster over remoting,无论是在这方面还是在一般情况下,集群将允许您对一个节点的离开和重新出现做出反应

不过,要保证消息的传递需要额外的考虑。这本书很好阅读,可以更好地理解它周围的问题