wajs
wajs

Reputation: 309

How to get message causing restart in Akka Persistence

I'm having PersistenceActor and I'd like to do something in it's preRestart method, basing on a message, which caused the restart. For regular actor that would be easy, as there is message passed to preRestart method:

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

However for PersistentActor that can't be done in that way, because each time None is passed as a message attribute. It is caused by that piece of code in 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)
  }
}
}

Does anyone know why None is passed there, losing the original message?

Upvotes: 2

Views: 112

Answers (1)

johanandren
johanandren

Reputation: 11479

this seems to be an oversight and something we should fix in Akka, I have opened a ticket to track fixing it: https://github.com/akka/akka/issues/21824

Upvotes: 1

Related Questions