我正在研究 Akka-Remoting 示例。在将序列化支持配置到 application.conf 文件之前它运行良好。但是,在启用序列化后,消息无法正确传递。
我可以在接收和发送消息时在远程和客户端应用程序上看到 DeadLetter 的日志。我认为正在交换消息,但没有传递给正确的参与者。
这是运行在akka-mircokernel中的远程计算器的conf文件。
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'.
在启用序列化之前一切正常。我无法弄清楚我缺少或做错了哪些配置选项。任何帮助表示赞赏。
编辑:我是否需要扩展我的 pojo 中的任何类才能使序列化正常工作?
最佳答案
如果更改序列化配置导致消息丢失,那么显然序列化一定会失败(我不会将其称为“启用”,因为序列化必须始终发生)。您配置为使用 protobuf 的类不适合该序列化程序,它只知道如何处理 com.google.protobuf.Message
。您将必须定义一个 protobuf 协议(protocol)定义,使用 protoc
对其进行编译,然后将生成的类用作消息或编写您自己的序列化程序,将您的消息类(如 MathOp)转换为它们的 protobuf 等价物。
Protobuf 不是自动的;您还可以查看 kryo,它有一个外部维护的 akka 模块。
关于java - Akka 远程处理 : Dead Letters after enabling Serialization,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20244394/