以编程方式创建远程参与者不起作用
Creating Remote Actors Programmatically is not working
我正在以编程方式创建远程 akka actor。
下面是程序-
package remoting.programatic.demo
import akka.actor.{ActorSystem, Props}
import com.typesafe.config.ConfigFactory
import remoting.config.demo.RemoteActor
object RemoteActorApp extends App {
val system = ActorSystem("RemoteNodeApp", ConfigFactory.load().getConfig("RemoteProgrammatically"))
val remoteActor = system.actorOf(Props[RemoteActor], name = "remoteActorAddr")
remoteActor ! "Hello!"
val actorSelection = system.actorSelection("akka.tcp://RemoteNodeApp@localhost:2553/user/remoteActorAddr")
Thread.sleep(4000L)
actorSelection ! "Hello!"
}
配置为 -
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 系统中成功创建。
知道为什么没有创建演员以及为什么消息总是变成死信。
谢谢
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()
发送消息,在这种情况下这是死信,因为远程 actor 收到的消息是从 actor 外部使用 tell
(!
) 发送的。也就是说,远程actor是创建成功,但是下面两条消息是非actor发送的,导致远程actor中的sender()
解析为死信:
remoteActor ! "Hello!"
...
actorSelection ! "Hello!"
来自 documentation(强调我的):
actorRef ! message
If invoked from within an Actor, then the sending actor reference will be implicitly passed along with the message and available to the receiving Actor in its sender(): ActorRef
member method. The target actor can use this to reply to the original sender, by using sender() ! replyMsg
.
If invoked from an instance that is not an Actor the sender will be deadLetters
actor reference by default.
从另一个 actor 发送消息,或使用 ask
模式(创建一个内部 actor 来处理回复)。
我正在以编程方式创建远程 akka actor。
下面是程序-
package remoting.programatic.demo
import akka.actor.{ActorSystem, Props}
import com.typesafe.config.ConfigFactory
import remoting.config.demo.RemoteActor
object RemoteActorApp extends App {
val system = ActorSystem("RemoteNodeApp", ConfigFactory.load().getConfig("RemoteProgrammatically"))
val remoteActor = system.actorOf(Props[RemoteActor], name = "remoteActorAddr")
remoteActor ! "Hello!"
val actorSelection = system.actorSelection("akka.tcp://RemoteNodeApp@localhost:2553/user/remoteActorAddr")
Thread.sleep(4000L)
actorSelection ! "Hello!"
}
配置为 -
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 系统中成功创建。
知道为什么没有创建演员以及为什么消息总是变成死信。
谢谢
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()
发送消息,在这种情况下这是死信,因为远程 actor 收到的消息是从 actor 外部使用 tell
(!
) 发送的。也就是说,远程actor是创建成功,但是下面两条消息是非actor发送的,导致远程actor中的sender()
解析为死信:
remoteActor ! "Hello!"
...
actorSelection ! "Hello!"
来自 documentation(强调我的):
actorRef ! message
If invoked from within an Actor, then the sending actor reference will be implicitly passed along with the message and available to the receiving Actor in its
sender(): ActorRef
member method. The target actor can use this to reply to the original sender, by usingsender() ! replyMsg
.If invoked from an instance that is not an Actor the sender will be
deadLetters
actor reference by default.
从另一个 actor 发送消息,或使用 ask
模式(创建一个内部 actor 来处理回复)。