Akka Remoting:启用序列化后的死信

时间:2013-11-27 13:57:00

标签: java scala serialization akka protocol-buffers

我正在研究一个Akka-Remoting的例子。在将序列化支持配置到 application.conf 文件之前,它运行正常。但是,启用序列化后,消息无法正确传递。

我可以在接收和发送消息时在远程和客户端应用程序上看到DeadLetter的日志。我认为消息正在被交换,但没有传递给合适的演员。

这是远程计算器的conf文件,它在akka-mircokernel中运行。

remoteCalculator {
  akka {
    actor {
      #serialize-messages = on

  #No need to define serializers: java and protobuf are supported by Akka.
  serializers {
    java = "akka.serialization.JavaSerializer"
    #akka-containers = "akka.remote.serialization.MessageContainerSerializer"
    proto = "akka.remote.serialization.ProtobufSerializer"
    #daemon-create = "akka.remote.serialization.DaemonMsgCreateSerializer"
 }

serialization-bindings {
  #"akka.actor.ActorSelectionMessage" = akka-containers
  #"com.google.protobuf.GeneratedMessage" = proto
  #"akka.remote.DaemonMsgCreate" = daemon-create
  "java.lang.Integer"       = proto
  "scala.Int"               = proto
  "akka.example.MathOp" = proto
  #"akka.example.Add"       = proto
  #"akka.example.Subtract" = proto
  #"akka.example.Multiply" = proto
  #"akka.example.Divide"    = proto
  "akka.example.MathResult"         = proto
  #"akka.example.AddResult"             = proto
  #"akka.example.SubtractResult"        = proto
  #"akka.example.MultiplicationResult" = proto
  #"akka.example.DivisionResult"        = proto 
}
provider = "akka.remote.RemoteActorRefProvider"
}
remote {
  log-received-messages = on
  log-sent-messages = on
  log-remote-lifecycle-events = on
  enabled-transports = ["akka.remote.netty.tcp"]
  netty.tcp {
    hostname = "IGLR000PBG3K8Y-ubuntu"
    port = 2555
    log-received-messages = on
    log-sent-messages = on
    log-remote-lifecycle-events = on
  }
 }
}
}

和计算器客户端应用程序的conf文件

LocalSys {
  akka {
    actor {
      #serialize-messages = on

  #No need to define serializers: java and protobuf are supported by Akka.
  serializers {
    java = "akka.serialization.JavaSerializer"
    #akka-containers = "akka.remote.serialization.MessageContainerSerializer"
    proto = "akka.remote.serialization.ProtobufSerializer"
    #daemon-create = "akka.remote.serialization.DaemonMsgCreateSerializer"
 }

serialization-bindings {
  #"akka.actor.ActorSelectionMessage" = akka-containers
  #"com.google.protobuf.GeneratedMessage" = proto
  #"akka.remote.DaemonMsgCreate" = daemon-create
  "java.lang.Integer"       = proto
  "scala.Int"               = proto
  "akka.example.MathOp" = proto
  #"akka.example.Add"       = proto
  #"akka.example.Subtract" = proto
  #"akka.example.Multiply" = proto
  #"akka.example.Divide"    = proto
  "akka.example.MathResult"         = proto
  #"akka.example.AddResult"             = proto
  #"akka.example.SubtractResult"        = proto
  #"akka.example.MultiplicationResult" = proto
  #"akka.example.DivisionResult"        = proto 
}
provider = "akka.remote.RemoteActorRefProvider"
}
remote {
  log-received-messages = on
  log-sent-messages = on
  log-remote-lifecycle-events = on
  enabled-transports = ["akka.remote.netty.tcp"]
  netty.tcp {
    hostname = "IGLR000PBG3K8Y-ubuntu"
    port = 2556
    log-received-messages = on
    log-sent-messages = on
    log-remote-lifecycle-events = on
  }
 }
}

}

以下是我在远程计算器控制台上可以看到的内容

[INFO] [11/27/2013 18:40:00.425] [CalculatorApplication-akka.actor.default-dispatcher-6] [akka://CalculatorApplication/system/transports/akkaprotocolmanager.tcp0/akkaProtocol-tcp%3A%2F%2FCalculatorApplication%4010.147.137.227%3A60905-1] Message [akka.remote.transport.ActorTransportAdapter$DisassociateUnderlying] from Actor[akka://CalculatorApplication/deadLetters] to Actor[akka://CalculatorApplication/system/transports/akkaprotocolmanager.tcp0/akkaProtocol-tcp%3A%2F%2FCalculatorApplication%4010.147.137.227%3A60905-1#-1343833615] was not delivered. [1] dead letters encountered. This logging can be turned off or adjusted with configuration settings 'akka.log-dead-letters' and 'akka.log-dead-letters-during-shutdown'.
[INFO] [11/27/2013 18:40:00.429] [CalculatorApplication-akka.actor.default-dispatcher-5] [akka://CalculatorApplication/system/transports/akkaprotocolmanager.tcp0/akkaProtocol-tcp%3A%2F%2FCalculatorApplication%4010.147.137.227%3A60905-1] Message [akka.remote.transport.AssociationHandle$Disassociated] from Actor[akka://CalculatorApplication/deadLetters] to Actor[akka://CalculatorApplication/system/transports/akkaprotocolmanager.tcp0/akkaProtocol-tcp%3A%2F%2FCalculatorApplication%4010.147.137.227%3A60905-1#-1343833615] was not delivered. [2] dead letters encountered. This logging can be turned off or adjusted with configuration settings 'akka.log-dead-letters' and 'akka.log-dead-letters-during-shutdown'.

并在计算器客户端控制台上

[INFO] [11/27/2013 18:40:00.343] [clientkernel-akka.actor.default-dispatcher-2] [akka://clientkernel/system/endpointManager/reliableEndpointWriter-akka.tcp%3A%2F%2FCalculatorApplication%40IGLR000PBG3K8Y-ubuntu.ampf.com%3A2555-0/endpointWriter/endpointReader-akka.tcp%3A%2F%2FCalculatorApplication%40IGLR000PBG3K8Y-ubuntu%3A2555-0] Message [akka.remote.transport.AssociationHandle$Disassociated] from Actor[akka://clientkernel/deadLetters] to Actor[akka://clientkernel/system/endpointManager/reliableEndpointWriter-akka.tcp%3A%2F%2FCalculatorApplication%40IGLR000PBG3K8Y-ubuntu.ampf.com%3A2555-0/endpointWriter/endpointReader-akka.tcp%3A%2F%2FCalculatorApplication%40IGLR000PBG3K8Y-ubuntu%3A2555-0#-773728878] was not delivered. [1] dead letters encountered. This logging can be turned off or adjusted with configuration settings 'akka.log-dead-letters' and 'akka.log-dead-letters-during-shutdown'.
[INFO] [11/27/2013 18:40:00.361] [clientkernel-akka.actor.default-dispatcher-3] [akka://clientkernel/system/transports/akkaprotocolmanager.tcp0/akkaProtocol-tcp%3A%2F%2FCalculatorApplication%40IGLR000PBG3K8Y-ubuntu%3A2555-1] Message [akka.remote.transport.AssociationHandle$Disassociated] from Actor[akka://clientkernel/deadLetters] to Actor[akka://clientkernel/system/transports/akkaprotocolmanager.tcp0/akkaProtocol-tcp%3A%2F%2FCalculatorApplication%40IGLR000PBG3K8Y-ubuntu%3A2555-1#-249262169] was not delivered. [2] dead letters encountered. This logging can be turned off or adjusted with configuration settings 'akka.log-dead-letters' and 'akka.log-dead-letters-during-shutdown'.

在启用序列化之前,一切正常。我无法弄清楚我错过了什么配置选项或做错了什么。任何帮助表示赞赏。

编辑:我是否需要在我的pojos中扩展任何类以使序列化正常工作?

1 个答案:

答案 0 :(得分:4)

如果更改序列化配置会导致消息丢失,那么显然序列化必定会失败(我不会将其称为“启用”,因为必须始终进行序列化)。您配置为使用protobuf的类不适合该序列化程序,该序列化程序仅知道如何处理com.google.protobuf.Message。您必须定义protobuf协议定义,使用protoc进行编译,然后使用生成的类作为消息,或者编写自己的序列化程序,将您的消息类(如MathOp)转换为其protobuf等效项。

Protobuf不是自动化的;您还可以查看kryo,其中有一个外部维护的akka​​模块。