演员停止 Akka 后排队的消息去哪里
Where do enqueued messages go after an actor is stopped Akka
所以我知道,如果您向死去的演员发送消息,该消息会转到 DeadLetters,但是已经为该演员排队的消息会发生什么。他们也被转发到那里还是迷路了?
一般来说,您不能对投递到死信进行过多假设。作为 docs on dead letters say:
Messages which cannot be delivered (and for which this can be ascertained) will be delivered to a synthetic actor called /deadLetters
. This delivery happens on a best-effort basis; it may fail even within the local JVM (e.g. during actor termination). Messages sent via unreliable network transports will be lost without turning up as dead letters.
但是,看起来 Akka 确实努力将已经为 actor 排队的消息转发到死信。这是来自 cleanup
function for Mailbox
的片段,它在 actor 关闭后被调用:
/**
* Overridable callback to clean up the mailbox,
* called when an actor is unregistered.
* By default it dequeues all system messages + messages and ships them to the owning actors' systems' DeadLetterMailbox
*/
protected[dispatch] def cleanUp(): Unit =
if (actor ne null) { // actor is null for the deadLetterMailbox
val dlm = actor.dispatcher.mailboxes.deadLetterMailbox
var messageList = systemDrain(new LatestFirstSystemMessageList(NoMessage))
while (messageList.nonEmpty) {
// message must be “virgin” before being able to systemEnqueue again
val msg = messageList.head
messageList = messageList.tail
msg.unlink()
dlm.systemEnqueue(actor.self, msg)
}
if (messageQueue ne null) // needed for CallingThreadDispatcher, which never calls Mailbox.run()
messageQueue.cleanUp(actor.self, actor.dispatcher.mailboxes.deadLetterMailbox.messageQueue)
}
}
所以我知道,如果您向死去的演员发送消息,该消息会转到 DeadLetters,但是已经为该演员排队的消息会发生什么。他们也被转发到那里还是迷路了?
一般来说,您不能对投递到死信进行过多假设。作为 docs on dead letters say:
Messages which cannot be delivered (and for which this can be ascertained) will be delivered to a synthetic actor called
/deadLetters
. This delivery happens on a best-effort basis; it may fail even within the local JVM (e.g. during actor termination). Messages sent via unreliable network transports will be lost without turning up as dead letters.
但是,看起来 Akka 确实努力将已经为 actor 排队的消息转发到死信。这是来自 cleanup
function for Mailbox
的片段,它在 actor 关闭后被调用:
/**
* Overridable callback to clean up the mailbox,
* called when an actor is unregistered.
* By default it dequeues all system messages + messages and ships them to the owning actors' systems' DeadLetterMailbox
*/
protected[dispatch] def cleanUp(): Unit =
if (actor ne null) { // actor is null for the deadLetterMailbox
val dlm = actor.dispatcher.mailboxes.deadLetterMailbox
var messageList = systemDrain(new LatestFirstSystemMessageList(NoMessage))
while (messageList.nonEmpty) {
// message must be “virgin” before being able to systemEnqueue again
val msg = messageList.head
messageList = messageList.tail
msg.unlink()
dlm.systemEnqueue(actor.self, msg)
}
if (messageQueue ne null) // needed for CallingThreadDispatcher, which never calls Mailbox.run()
messageQueue.cleanUp(actor.self, actor.dispatcher.mailboxes.deadLetterMailbox.messageQueue)
}
}