concept process in category akka
appears as: processes, process, The process, processes, process

This is an excerpt from Manning's book Reactive Design Patterns.
Most of these issues are dealt with using the resource-management patterns discussed in chapter 14. The basic principle is to retrofit the needed encapsulation and asynchronous boundaries by interacting with the resource within a dedicated Reactive component, using extra threads, processes, or machines as necessary. This allows these resources to be integrated seamlessly into the architecture.
Listing 15.19. Adding persistence to the budget messages
case class AliceConfirmedChange(deliveryId: Long) case class AliceDeniedChange(deliveryId: Long) class PersistentSam(alice: ActorPath, bob: ActorPath, amount: BigDecimal, override val persistenceId: String) extends PersistentActor with AtLeastOnceDelivery { def receiveCommand = Actor.emptyBehavior #1 override def preStart(): Unit = context.become(talkToAlice()) #2 def talkToAlice() = { var deliveryId: Long = 0 #3 deliver(alice)(id => { deliveryId = id ChangeBudget(-amount, self, persistenceId) }) { case ChangeBudgetDone => persist(AliceConfirmedChange(deliveryId)) { ev => confirmDelivery(ev.deliveryId) context.become(talkToBob()) } case CannotChangeBudget(reason) => persist(AliceDeniedChange(deliveryId)) { ev => confirmDelivery(ev.deliveryId) context.stop(self) } } } def talkToBob() = ... #4 def receiveRecover = { case AliceConfirmedChange(deliveryId) => confirmDelivery(deliveryId) context.become(talkToBob()) case AliceDeniedChange(deliveryId) => confirmDelivery(deliveryId) context.stop(self) } } #1 - Due to an implementation restriction, “deliver” does not work from here. #2 - Therefore, you start the process from the preStart lifecycle hook. #3 - Instead of letting the delivery ID travel with the message, you keep it here because there can be only this one message on its way. #4 - Analog to the previous code