为什么在尝试使用断点调试akka actor时会收到死信?

时间:2017-03-30 20:04:56

标签: scala akka akka-persistence dead-letter

我设置了一个断点here

package sample.persistence

//#persistent-actor-example
import akka.actor._
import akka.persistence._

case class Cmd(data: String)
case class Evt(data: String)

case class ExampleState(events: List[String] = Nil) {
  def updated(evt: Evt): ExampleState = copy(evt.data :: events)
  def size: Int = events.length
  override def toString: String = events.reverse.toString
}

class ExamplePersistentActor extends PersistentActor {
  override def persistenceId = "sample-id-1"

  var state = ExampleState()

  def updateState(event: Evt): Unit =
    state = state.updated(event)

  def numEvents =
    state.size

  val receiveRecover: Receive = {
    case evt: Evt                                 => updateState(evt)
    case SnapshotOffer(_, snapshot: ExampleState) => state = snapshot  
                                                  ^^^^^^^ BREAKPOINT ^^^^^
  }

  val receiveCommand: Receive = {
    case Cmd(data) =>
      persist(Evt(s"${data}-${numEvents}"))(updateState)
      persist(Evt(s"${data}-${numEvents + 1}")) { event =>
        updateState(event)
        context.system.eventStream.publish(event)
      }
    case "snap"  => saveSnapshot(state)
    case "print" => println(state)
  }

}
//#persistent-actor-example

object PersistentActorExample extends App {

  val system = ActorSystem("example")
  val persistentActor = system.actorOf(Props[ExamplePersistentActor], "persistentActor-4-scala")

  persistentActor ! Cmd("foo")
  persistentActor ! Cmd("baz")
  persistentActor ! Cmd("bar")
  persistentActor ! "snap"
  persistentActor ! Cmd("buzz")
  persistentActor ! "print"

  Thread.sleep(10000)
  system.terminate()
}

我得到了:

[INFO] [03/30/2017 22:53:40.141] [example-akka.actor.default-dispatcher-3] [akka://example/user/persistentActor-4-scala] Message [java.lang.String] from Actor[akka://example/deadLetters] to Actor[akka://example/user/persistentActor-4-scala#-1598116294] 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] [03/30/2017 22:53:40.142] [example-akka.actor.default-dispatcher-3] [akka://example/user/persistentActor-4-scala] Message [sample.persistence.Cmd] from Actor[akka://example/deadLetters] to Actor[akka://example/user/persistentActor-4-scala#-1598116294] 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'.
[INFO] [03/30/2017 22:53:40.142] [example-akka.actor.default-dispatcher-3] [akka://example/user/persistentActor-4-scala] Message [sample.persistence.Cmd] from Actor[akka://example/deadLetters] to Actor[akka://example/user/persistentActor-4-scala#-1598116294] was not delivered. [3] 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] [03/30/2017 22:53:40.142] [example-akka.actor.default-dispatcher-3] [akka://example/user/persistentActor-4-scala] Message [sample.persistence.Cmd] from Actor[akka://example/deadLetters] to Actor[akka://example/user/persistentActor-4-scala#-1598116294] was not delivered. [4] 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] [03/30/2017 22:53:40.142] [example-akka.actor.default-dispatcher-3] [akka://example/user/persistentActor-4-scala] Message [java.lang.String] from Actor[akka://example/deadLetters] to Actor[akka://example/user/persistentActor-4-scala#-1598116294] was not delivered. [5] 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] [03/30/2017 22:53:40.142] [example-akka.actor.default-dispatcher-9] [akka://example/user/persistentActor-4-scala] Message [sample.persistence.Cmd] from Actor[akka://example/deadLetters] to Actor[akka://example/user/persistentActor-4-scala#-1598116294] was not delivered. [6] 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] [03/30/2017 22:53:40.143] [example-akka.actor.default-dispatcher-9] [akka://example/user/persistentActor-4-scala] Message [java.lang.String] from Actor[akka://example/deadLetters] to Actor[akka://example/user/persistentActor-4-scala#-1598116294] was not delivered. [7] 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'.
Disconnected from the target VM, address: '127.0.0.1:53432', transport: 'socket'

Process finished with exit code 0
  • 为什么会这样?

  • 为什么我会收到死信?

  • 是因为消息超时吗?

  • 如果是,有没有办法将超时间隔设置为无限?

  • 如果原因是别的,那么有没有办法确保使用断点调试不会出现死信?

0 个答案:

没有答案