【发布时间】:2018-09-06 13:04:17
【问题描述】:
我有一个应用程序,它运行一个带有主管的演员系统,该主管可以通过 akka 远程处理接收消息。从远程参与者系统发送的消息是案例类,例如:
case class SupervisorStartChannel(channelName: String) extends SupervisorRequest
case class SupervisorShutdown() extends SupervisorRequest
在我的接收中,我有以下内容:
def receive: Actor.Receive = LoggingReceive ({
case SupervisorListChannels =>
listChannels()
case SupervisorReportComponents =>
sender ! loadConfiguredComponents()
case SupervisorStartChannel(channelName) =>
sender ! startChannelByName(channelName)
case SupervisorShutdown =>
log.info("Shutdown received.")
sender ! SupervisorAck
context.system.terminate()
case _ =>
replayError(s"$supervisorName can't process an empty command.")
}: Receive) andThen metered.Receive
如果我从主管运行的同一个actor系统内部发送一个SupervisorShutdown,它会进入正确的case,但是当从远程系统发送SupervisorShutdown()时,它会进入case_。虽然发送 SupervisorStartChannel(channel1) 工作正常。
编辑:运行一些测试后,我发现问题出在case class SupervisorShutdown() extends SupervisorRequest 的序列化上。 Akka 使用默认的 Java 序列化程序进行远程处理,这就是导致它的原因。
知道是什么原因造成的吗?
【问题讨论】:
-
您是否尝试在案例子句中添加括号:
case SupervisorShutdown() =>或使用对象而不是案例类:object SupervisorShutdown? -
@dyrkin 是的,我做到了,而且由于内部消息(在同一个参与者系统中)确实有效,让我相信这是远程处理的问题。
-
经过额外测试,我发现这是序列化的问题。 ActorSystem -> ActorSystem 消息正在被序列化。并且由于
case class SupervisorShutdown() extends SupervisorRequest是使用默认 Java 序列化程序序列化的,因此未正确接收。