akka演员中的前锋和告诉之间的区别

Mic*_*zuk 58 scala actor akka

如果我发送相同的消息,告诉和转发有什么区别:

case msg: Message =>
  otherActor tell (msg,sender)
Run Code Online (Sandbox Code Playgroud)

case msg: Message =>
  otherActor forward msg
Run Code Online (Sandbox Code Playgroud)

Kon*_*ski 107

sender()将是在接收端的不同.


使用tell(也称为!)发送消息:

A 告诉消息MB.
B 告诉那条消息C.
C认为sender()消息MB.


消息使用转发发送:

A 告诉消息MB.将该消息
B 转发C.
C认为sender()消息MA.



值得指出的是,你可以实现与forward使用明确设置消息发送者时相同的功能tell,但这不是典型的Akka风格:

// inside `B`, when received `msg` from `A`
C tell (msg, A) 
      == 
C forward msg
Run Code Online (Sandbox Code Playgroud)



有关更多信息,请参阅有关转发文档.

  • 实际上在他的情况下,他使用`tell(msg,sender)`,然后相当于forward.对? (5认同)
  • 是的,这正是如何实现前进:`def forward(消息:Any)(隐式上下文:ActorContext)= tell(message,context.sender())`:-)快乐的hakking! (5认同)

mon*_*ack 15

Tell将发件人设置为发送邮件的actor.

转发会保留邮件的原始发件人.

  • 加 1 以保持简单 (2认同)