首页 > 解决方案 > Akka 演员没有收到案例类 [Akka 远程处理](序列化问题)

问题描述

我有一个应用程序,它运行一个带有主管的演员系统,可以通过 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,它会进入正确的案例,但是当从远程系统发送SupervisorShutdown()时,它会进入案例_。虽然发送 SupervisorStartChannel(channel1) 工作正常。

编辑:运行一些测试后,我发现问题来自于case class SupervisorShutdown() extends SupervisorRequest. Akka 使用默认的 Java 序列化程序进行远程处理,这就是导致它的原因。

知道是什么原因造成的吗?

标签: scalaakka

解决方案


正如@dyrkin 建议的那样,在运行了几个测试之后,通过使用SupervisorShutdown()而不是解决了这个问题SupervisorShutdown,然后也与SupervisorShutdown().


推荐阅读