0

我正在以编程方式创建远程 akka 演员。

以下是程序 -

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 演员系统上没有成功创建。任何想法为什么不创建演员以及为什么消息总是变成死信。谢谢。

4

1 回答 1

1
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( ) 发送的。!换句话说,远程actor创建成功,但是从非actor发送了以下两条消息,这导致sender()远程actor解析为死信:

remoteActor ! "Hello!"
...
actorSelection ! "Hello!"

文档(强调我的):

actorRef ! message

如果从 Actor 内部调用,则发送 Actor 引用将与消息一起隐式传递,并在其sender(): ActorRef成员方法中可供接收 Actor 使用。目标参与者可以使用它来回复原始发件人,使用sender() ! replyMsg.

如果从非 Actor 的实例调用,则deadLetters默认情况下发送者将是 Actor 引用。

从另一个参与者发送消息,或使用ask模式(创建一个内部参与者来处理回复)。

于 2017-12-28T18:17:03.563 回答