How to develop Akka Persistence Actors
Before diving into the development of Akka Persistence application, we will consider some steps on how to develop an Akka Persistence Actor, covering which components are important, which functions are required to provide implementation, how to interact with Journals, and so on.
Step1 – Use the PersistenceActor trait
If want to develop an Akka Persistence component or Actor, add the PersistenceActor
trait to this Actor, as shown here:
class HelloWorldActor extends PersistentActor{ // Actor State goes here // Actor Operations goes here }
Here, PersistentActor
is a trait defined in the akka.persistence
package. It marks our HelloWorldActor
as a Persistence Actor.
Step2 – Implement PersistenceActor's receiveRecover
The next step is to provide an implementation for one of the important and mandatory functions (or methods) of PersistentActor
trait—receiveRecover
. It is defined with the following signature:
def receiveRecover: Receive
This function is also...