如何在Akka Persistence中获取导致重启的消息

时间:2016-11-09 12:34:03

标签: scala akka akka-persistence

我有PersistenceActor并且我想在其preRestart方法中做一些事情,基于导致重启的消息。对于常规演员来说很容易,因为有消息传递给preRestart方法:

def preRestart(reason: Throwable, message: Option[Any])

然而,PersistentActor无法以这种方式完成,因为每次None都作为消息属性传递。它是由Eventsourced.scala

中的那段代码引起的
override protected[akka] def aroundPreRestart(reason: Throwable, message: Option[Any]): Unit = {
try {
  internalStash.unstashAll()
  unstashAll(unstashFilterPredicate)
} finally {
  message match {
    case Some(WriteMessageSuccess(m, _)) ⇒
      flushJournalBatch()
      super.aroundPreRestart(reason, Some(m))
    case Some(LoopMessageSuccess(m, _)) ⇒
      flushJournalBatch()
      super.aroundPreRestart(reason, Some(m))
    case Some(ReplayedMessage(m)) ⇒
      flushJournalBatch()
      super.aroundPreRestart(reason, Some(m))
    case mo ⇒
      flushJournalBatch()
      super.aroundPreRestart(reason, None)
  }
}
}

有谁知道为什么None在那里传递,丢失了原始信息?

1 个答案:

答案 0 :(得分:1)

这似乎是一种疏忽,我们应该在Akka中解决这个问题,我已经开了一张票来跟踪修复它:https://github.com/akka/akka/issues/21824