2017-10-16 125 views
0

我正在使用Akka集群,我有一个有趣的问题。我在节点A上有一个演员Actor1(akka.tcp://[email protected]:2554)。此演员发现使用Akka集群 - 来自死信的消息?

val actor2sel = context.actorSelection(RootActorPath(m.address)/"user"/"actor2") 

m哪里是集群的成员的另一节点上的另一行动者。 actor2sel是

ActorSelection[Anchor(akka.tcp://[email protected]:2553/), Path(/user/actor2)] 

后来,Actor1转发消息Actor2,它正确地得到消息,但发件人是deadLetters:

akka.tcp://[email protected]:2554/deadLetters 

你有什么原因可以是任何指针?

回答

1

转发邮件才有意义,如果至少有三个演员在消息链:

actor1 --[sends Messsage1]--> actor2 --[forwards Message1]--> actor3 

actor3

def receive = { 
    case Message1 => 
    sender ! Response1 
} 

sender以上是actor1基准,在上述的消息链。

如果只有两个演员参与,转发是不正确的工具:

actor1 --[forwards Message1]--> actor2 

actor2,如果在消息链转发来自actor1一个Message1,没有“以前”的演员,然后发件人将是一纸空文:

def receive = { 
    case Message1 => 
    sender ! Response1 
    // sender is dead letters if there are only two actors in the forwarding chain 
} 

如果Actor1不转发该消息Actor2之前接收来自另一演员的消息,只是有Actor1发送(!)的消息Actor2而不是转发它。

如果Actor1在转发之前确实收到来自其他演员的消息,请确保此演员在Actor2访问sender之前正在运行。