如何从被隔离的系统中检测隔离状态〜?
我在下面看到这个日志:
[warn] Remoting - Tried to associate with unreachable remote address [akka.tcp://Application@192.168.0.15:6000]. Address is now gated for 5000 ms, all messages to this address will be delivered to dead letters. Reason: The remote system has quarantined this system. No further associations to the remote system are possible until this system is restarted.
但我不确定如何通过代码对此作出反应。
我找到了这个帖子:Recovering from the Quarantined state,建议侦听QuarantinedEvent
,但不会在系统被隔离上调度。
我实际上听了所有RemotingLifecycleEvent
并发现了这个:
AssociationError [akka.tcp://Application@192.168.0.100:2552] -> [akka.tcp://Application@192.168.0.15:6000]: Error [Invalid address: akka.tcp://Application@192.168.0.15:6000] [akka.remote.InvalidAssociation: Invalid address: akka.tcp://Application@192.168.0.15:6000
Caused by: akka.remote.transport.Transport$InvalidAssociationException: The remote system has quarantined this system. No further associations to the remote system are possible until this system is restarted.]
但这只是一个AssociationError
,由于其他许多原因也会被调度,我是否必须在错误中搜索实际文本"The remote system has quarantined this system."
以确定?
答案 0 :(得分:5)
是的,您的建议有效,可以按照以下方式完成
订阅演员akka.remote.AssociationErrorEvent
override def preStart(): Unit = {
context.system.eventStream.subscribe(self, classOf[akka.remote.AssociationErrorEvent])
}
然后在receive
方法
override def receive: Receive = {
case e:AssociationErrorEvent =>
log.info(s"AssociationErrorEvent: $e")
if (e.cause.getCause.getMessage.contains("quarantined this system")) {
log.warning(s"We got quarantined")
}
}
答案 1 :(得分:1)
在William Carter评论之后:
Akka提供了不需要检查邮件内容的适当事件。
class MyActor extends Actor with ActorLogging {
override def preStart(): Unit = {
super.preStart()
context.system.eventStream.subscribe(context.self, classOf[ThisActorSystemQuarantinedEvent])
}
override def receive: Receive = {
case ev: ThisActorSystemQuarantinedEvent => log.warning(s"I was quarantined by ${ev.remoteAddress}")
}
}