代码之家  ›  专栏  ›  技术社区  ›  Fede E.

Akka actor没有收到case类[Akka remoting](序列化问题)

  •  0
  • Fede E.  · 技术社区  · 6 年前

    我有一个运行actor系统的应用程序,它有一个可以通过akkaremoting接收消息的主管。从远程参与者系统发送的消息是案例类,例如:

    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
    

    如果我从运行supervisor的同一actor系统内部发送SupervisorShutdown,它将输入正确的大小写,但是从远程系统发送SupervisorShutdown()时,它将输入大小写\。当发送一个SupervisorStartChannel(channel1)时,它可以完美地工作。

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

    你知道这是什么原因吗?

    1 回复  |  直到 6 年前
        1
  •  -1
  •   Fede E.    6 年前

    正如@dyrkin所建议的,在运行了几个测试之后,通过使用 SupervisorShutdown() SupervisorShutdown ,然后与 主管关机() .