in pekko-sample-persistence-dc-scala/src/main/scala/sample/persistence/res/bank/BankAccount.scala [79:92]
def detectOverdrawn(
state: BankAccount.State, replicationContext: ReplicationContext, context: ActorContext[Command]): Unit = {
if (replicationContext.concurrent // this event happened concurrently with other events already processed
&& replicationContext.replicaId == ReplicaId("eu-central") // if we only want to do the side effect in a single DC
&& !replicationContext.recoveryRunning // probably want to avoid re-execution of side effects during recovery
) {
// there's a chance we may have gone into the overdraft due to concurrent events due to concurrent requests
// or a network partition
if (state.balance < 0) {
// the trigger could happen here, in a projection, or as done here by sending a command back to self so that an event can be stored
context.self ! AlertOverdrawn(state.balance)
}
}
}