我有两个在本地运行的docker容器,一个是master容器,第二个是slave容器,通过akka远程通信。对于某些消息,从站可能会不时进行OOM操作,在这种情况下,泊坞窗会正常重启它。.
代码看起来像这样:
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.
所以我的问题是,一旦从属设备重新启动并发送所有挂起的消息(在关闭期间无法传送),我如何强制主服务器重新连接从属设备?
答案 0 :(得分:0)
我建议直接使用Akka群集而不是远程处理,为此,以及一般而言,群集将允许您listen for membership events,以便您可以对离开并重新出现的节点做出反应。
尽管要保证围绕消息的传递,但还需要一些额外的考虑。 This section of the docs很容易阅读,可以更好地理解其周围的问题。