创建远程演员以编程方式不起作用
我正在以编程方式创建远程演员演员。创建远程演员以编程方式不起作用
以下是节目 -
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://[email protected]:2553/user/remoteActorAddr")
Thread.sleep(4000L)
actorSelection ! "Hello!"
}
的配置 -
RemoteProgrammatically { akka {
actor {
provider = "akka.remote.RemoteActorRefProvider"
deployment {
/remoteActorAddr {
remote = "akka.tcp://[email protected]: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://[email protected]:2553]
[INFO] [12/27/2017 10:37:30.379] [main] [akka.remote.Remoting] Remoting now listens on addresses: [akka.tcp://[email protected]: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参与者系统上成功创建。 任何想法为什么演员没有创建,为什么消息总是进入死信。 谢谢。
回答:
Message [java.lang.String] from Actor[akka://RemoteNodeApp/user/remoteActorAddr#-766312407] to Actor[akka://RemoteNodeApp/deadLetters] was not delivered. [1] dead letters encountered.
以上节选自你的记录是说从远程演员发送字符串消息当死信件邮箱遇到。远程演员显然发送消息给sender()
,在这种情况下,这是一个死信,因为远程演员收到的消息是从演员外部以tell
(!
)发送的。换句话说,远程演员是成功创建,但以下两个消息是从非演员,这会导致sender()
远程演员来解决死字母发送:
remoteActor ! "Hello!"
...
actorSelection ! "Hello!"
从documentation(重点煤矿):
actorRef ! message
如果一个演员内调用,然后对这个角色的参考将被隐随消息一起传递的d可用于接收Actor的
sender(): ActorRef
成员方法。目标演员可以使用这个来回复原始发件人,使用sender() ! replyMsg
。如果从不是Actor的实例调用,发件人将默认为
deadLetters
actor参考。
从另一个演员发送消息,或使用ask
图案(其创建内部演员来处理答复)。
以上是 创建远程演员以编程方式不起作用 的全部内容, 来源链接: utcz.com/qa/266203.html