我正在以编程方式创建远程akka actor。
以下是计划 -
RemoteProgrammatically {
akka {
actor {
provider = "akka.remote.RemoteActorRefProvider"
deployment {
/remoteActorAddr {
remote = "akka.tcp://RemoteNodeApp@localhost:2553"
}
}
}
remote {
enabled-transports = ["akka.remote.netty.tcp"]
netty.tcp {
hostname = "localhost"
port = 2553
}
}
}
}
配置为 -
[INFO] [12/27/2017 10:37:30.053] [main] [akka.remote.Remoting] Starting remoting
[INFO] [12/27/2017 10:37:30.378] [main] [akka.remote.Remoting] Remoting started; listening on addresses :[akka.tcp://RemoteNodeApp@localhost:2553]
[INFO] [12/27/2017 10:37:30.379] [main] [akka.remote.Remoting] Remoting now listens on addresses: [akka.tcp://RemoteNodeApp@localhost:2553]
[INFO] [12/27/2017 10:37:30.418] [RemoteNodeApp-akka.actor.default-dispatcher-14] [akka://RemoteNodeApp/deadLetters] Message [java.lang.String] from Actor[akka://RemoteNodeApp/user/remoteActorAddr#-766312407] to Actor[akka://RemoteNodeApp/deadLetters] 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] [12/27/2017 10:37:34.419] [RemoteNodeApp-akka.actor.default-dispatcher-14] [akka://RemoteNodeApp/deadLetters] Message [java.lang.String] from Actor[akka://RemoteNodeApp/user/remoteActorAddr#-766312407] to Actor[akka://RemoteNodeApp/deadLetters] 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'.
运行程序后的输出是 -
remoteActorAddr
我发给演员的信息总是进入死信。
看起来在RemoteNodeApp actor系统上未成功创建sf2
。
任何想法为什么没有创建演员以及为什么消息总是进入死信。
感谢。
答案 0 :(得分:1)
Message [java.lang.String] from Actor[akka://RemoteNodeApp/user/remoteActorAddr#-766312407] to Actor[akka://RemoteNodeApp/deadLetters] was not delivered. [1] dead letters encountered.
上面的日志摘录说,当从远程actor发送字符串消息时会遇到死信邮箱。远程演员显然正在向sender()
发送消息,在这种情况下这是死信,因为远程演员收到的消息是从演员外部用tell
(!
)发送的。换句话说,远程actor 是成功创建的,但是以下两个消息是从非actor发送的,这会导致远程actor中的sender()
解析为死信:
remoteActor ! "Hello!"
...
actorSelection ! "Hello!"
来自documentation(强调我的):
actorRef ! message
如果从Actor内调用,则发送actor引用将与消息一起隐式传递,并在其
sender(): ActorRef
成员方法中可用于接收Actor。目标参与者可以使用此sender() ! replyMsg
来回复原始发件人。如果从不是Actor的实例调用,默认情况下发件人将是
deadLetters
actor引用。
从另一个actor发送消息,或使用ask
模式(创建一个内部actor来处理回复)。