+per #15327 Add AtLeastOnceDelivery trait
* also remove final of around methods, and let deliver send when not recoveryRunning (cherry picked from commit 312b0d107a179accaf135f64ed9c3b78f3e351d1)
This commit is contained in:
parent
4ad346afd4
commit
32ca608c97
18 changed files with 2969 additions and 15 deletions
|
|
@ -9,7 +9,6 @@ import akka.persistence._
|
|||
|
||||
import scala.concurrent.duration._
|
||||
import scala.language.postfixOps
|
||||
|
||||
trait PersistenceDocSpec {
|
||||
val config =
|
||||
"""
|
||||
|
|
@ -133,6 +132,48 @@ trait PersistenceDocSpec {
|
|||
}
|
||||
}
|
||||
|
||||
new AnyRef {
|
||||
//#at-least-once-example
|
||||
import akka.actor.{ Actor, ActorPath, Props }
|
||||
import akka.persistence.AtLeastOnceDelivery
|
||||
|
||||
case class Msg(deliveryId: Long, s: String)
|
||||
case class Confirm(deliveryId: Long)
|
||||
|
||||
sealed trait Evt
|
||||
case class MsgSent(s: String) extends Evt
|
||||
case class MsgConfirmed(deliveryId: Long) extends Evt
|
||||
|
||||
class MyPersistentActor(destination: ActorPath)
|
||||
extends PersistentActor with AtLeastOnceDelivery {
|
||||
|
||||
def receiveCommand: Receive = {
|
||||
case s: String => persist(MsgSent(s))(updateState)
|
||||
case Confirm(deliveryId) => persist(MsgConfirmed(deliveryId))(updateState)
|
||||
}
|
||||
|
||||
def receiveRecover: Receive = {
|
||||
case evt: Evt => updateState(evt)
|
||||
}
|
||||
|
||||
def updateState(evt: Evt): Unit = evt match {
|
||||
case MsgSent(s) =>
|
||||
deliver(destination, deliveryId => Msg(deliveryId, s))
|
||||
|
||||
case MsgConfirmed(deliveryId) => confirmDelivery(deliveryId)
|
||||
}
|
||||
}
|
||||
|
||||
class MyDestination extends Actor {
|
||||
def receive = {
|
||||
case Msg(deliveryId, s) =>
|
||||
// ...
|
||||
sender() ! Confirm(deliveryId)
|
||||
}
|
||||
}
|
||||
//#at-least-once-example
|
||||
}
|
||||
|
||||
new AnyRef {
|
||||
//#channel-example
|
||||
import akka.actor.{ Actor, Props }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue