当我试图在我的本地主机上使用远程akka角色运行一个简单的示例时,我遇到了死信。
这是我的远程项目的build.sbt文件。
name := "HelloRemote"
version := "1.0"
scalaVersion := "2.11.2"
resolvers += "Typesafe Repository" at "http://repo.typesafe.com/typesafe/releases/"
libraryDependencies ++= Seq(
"com.typesafe.akka" %% "akka-actor" % "2.3.6",
"com.typesafe.akka" %% "akka-remote" % "2.3.6"
)这是我用于远程系统的application.conf文件。
akka {
actor {
provider = "akka.remote.RemoteActorRefProvider"
}
remote {
enabled-transports = ["akka.remote.netty.tcp"]
netty.tcp {
hostname = "127.0.0.1"
port = 5100
}
}
}这是我的远程系统的HelloRemote.scala文件。
package remote
import akka.actor._
object HelloRemote extends App {
val system = ActorSystem("HelloRemoteSystem")
val remoteActor = system.actorOf(Props[RemoteActor], name = "RemoteActor")
remoteActor ! "The RemoteActor is alive"
}
class RemoteActor extends Actor {
def receive = {
case msg: String =>
println(s"RemoteActor received message '$msg'")
sender ! "Hello from the RemoteActor"
}
}对于我的本地系统,build.sbt文件如下所示。
name := "HelloLocal"
version := "1.0"
scalaVersion := "2.11.2"
resolvers += "Typesafe Repository" at "http://repo.typesafe.com/typesafe/releases/"
libraryDependencies ++= Seq(
"com.typesafe.akka" %% "akka-actor" % "2.3.6",
"com.typesafe.akka" %% "akka-remote" % "2.3.6"
)我的本地系统的application.conf文件是
akka {
actor {
provider = "akka.remote.RemoteActorRefProvider"
}
remote {
enabled-transports = ["akka.remote.netty.tcp"]
netty.tcp {
hostname = "127.0.0.1"
port = 0
}
}
}我的本地系统的HelloLocal.scala文件是
package local
import akka.actor._
object Local extends App {
val system = ActorSystem("LocalSystem")
val localActor = system.actorOf(Props[LocalActor], name = "LocalActor") // the local actor
localActor ! "START" // start the action
}
class LocalActor extends Actor {
// create the remote actor
val remote = context.actorSelection("akka.tcp://HelloRemoteSystem@127.0.0.1:5100/user/RemoteActor")
var counter = 0
def receive = {
case "START" =>
remote ! "Hello from the LocalActor"
case msg: String =>
println(s"LocalActor received message: '$msg'")
if (counter < 5) {
sender ! "Hello back to you"
counter += 1
}
}
}当我第一次运行HelloRemote.scala时,The RemoteActor is alive按照预期打印出来,然后立即得到错误信息
[INFO] [09/16/2014 10:52:47.585] [HelloRemoteSystem-akka.actor.default-dispatche
r-4] [akka://HelloRemoteSystem/deadLetters] Message [java.lang.String] from Acto
r[akka://HelloRemoteSystem/user/RemoteActor#1051175275] to Actor[akka://HelloRem
oteSystem/deadLetters] was not delivered. [1] dead letters encountered. This log
ging can be turned off or adjusted with configuration settings 'akka.log-dead-le
tters' and 'akka.log-dead-letters-during-shutdown'.当我运行本地系统HelloLocal.scala时,我得到了一个类似的错误,然后什么也没有发生。我是不是做错了什么?
发布于 2014-09-16 23:57:26
当您从参与者外部发送消息时,Akka会以发送者的身份填写死信邮箱。当HelloRemote.scala中的RemoteActor回复时,它是在回复死信邮箱,因为它收到的消息是从参与者外部发送的。
目前,HelloRemote.scala甚至不涉及远程处理,因为您只部署了一个本地参与者。
当您运行HelloLocal.scala时,我怀疑您的HelloRemote参与者系统正在终止,因为没有任何东西可以让它继续运行。
发布于 2016-03-12 23:55:43
我以前也遇到过同样的问题,我使用val config = ConfigFactory.parsingString("---Configuration---")而不是配置文件解决了这个问题。希望它能为你工作。
发布于 2016-03-02 16:15:44
我在做同样的例子时也遇到了这个问题。我遗漏的部分是将application.conf放在src/main/resources目录中。
如果在启动服务器时它位于正确的位置,您应该会看到这样的信息消息:
[INFO] [03/02/2016 19:06:10.365] [main] [akka.remote.Remoting] Starting remoting
[INFO] [03/02/2016 19:06:10.497] [main] [akka.remote.Remoting] Remoting started; listening on addresses : akka.tcp://HelloRemoteSystem@127.0.0.1:5100]
[INFO] [03/02/2016 19:06:10.499] [main] [akka.remote.Remoting] Remoting now listens on addresses: [akka.tcp://HelloRemoteSystem@127.0.0.1:5100]我使用的blog post的目录结构如下:
HelloRemote/
|-- build.sbt
|-- src
|-- main
│ |-- java
│ |-- resources
│ │ +-- application.conf <--------------------------
│ +-- scala
│ +-- remote
│ +-- HelloRemote.scala
+-- test
|-- java
|-- resources
+-- scala正如Ryan已经提到的,死信错误是字符串消息"The RemoteActor is alive“不是参与者的副作用,因此它不能接收回消息"Hello from the RemoteActor”。这是示例中的一个小错误,但不会导致远程参与者和本地参与者无法相互交谈的失败。
https://stackoverflow.com/questions/25872056
复制相似问题