Spring Boot Akka Event Sourcing Starter – Part 2

Now we will continue in part 2 to explain the starter itself into more details :

FlowContext

The Tookit Starter Is An Abstraction For The Following :

  1. How to define persistent entity actors for your aggregate plus the integration with spring
  2. Aggregate flow DSL abstraction for how to handle commands and events plus asynchronous command actions which is not highly recommend as your aggregate should be your transaction boundary context and should own its contextual data as well
  3. Cluster sharding abstraction for your created persistent entities plus make it configurable via spring
  4. Actor system configuration and integration with spring boot

Let us go over the points mentioned above quickly then in part 3 i will share a complete working example to act as a reference about how to use the event sourcing toolkit starter

The Generic Persistent Entity Class In The Starter :

the main abstracted entity class is  PersistentEntity class : The root entity class

which extend AbstractPersistentActor from Akka persistance toolkit , it has all common and abstracted technical functionalities for how to define persistent actors and just let you focus on the business flow of your aggregate logic .

The Aggregate Flow DSL Overview :

the flow as mentioned before in part 1 , it just abstract the way of how to define a flow of commands and events handling plus the responses needed to be sent back to the sender if any , please check part 1 for more deep flow explanation , I will just cover here the technical overview quickly plus we will see concrete example for how define the flow in part 3

The flow context when command is received will be initiated with the current state before handling the command and then based into the defined flow in your aggregate , the command or event will be handled accordingly .

The flow context overview :

Screen Shot 2018-04-23 at 12.49.14.png

then the actions will be generated from flow command handlers or event handlers based into the class diagram above are :

  1. Persist one generated event then do post action if any
  2. Persist list of generated events then do post action if any
  3. No generated events to persist and just do post action if any (read only commands case)

Screen Shot 2018-04-23 at 12.48.52.png

The cluster Sharding abstraction into the toolkit starter :

the 2 main classes that abstract cluster sharding and do the spring integration are  PersistentEntitySharding and PersistentEntityBroker , you can check the code for more details .

  • PersistentEntitySharding abstract the cluster sharding creation per Entity based into its configuration via the starter : code reference
  • PersistentEntityBroker is the broker to get the persistent entity shard in a abstracted way from your calling service by just passing the aggregate class type

Screen Shot 2018-04-23 at 12.57.50

The actor system integration with spring configuration and how it can be configured via spring configuration reference :

There is a specific interface need to be extended when you need to configure your entity bean which is PersistentEntityProperties where you can configure many properties as being shown into the class diagram below , in part 3  we will see a concrete example of its usage :

Screen Shot 2018-04-23 at 13.07.47.png

  1. snspshotStateAfter property is to snapshot the state after specific configured periodic time
  2. entityPassivateAfter to passivate the entity actor after configured time
  3. tags is the event tags used to tag events before storing them into the event store
  4. numberOfshards : configuration of the number of cluster shards for this entity
  5. persistentIdPostfix and PersistenceIdProfix : used for the unique aggregate Id within the shard .
  6. asyncPersistentEntityDispatcherName :  the name of the configure Akka dispatcher to be use for the Async actions within the aggregate actor
  7. pipeDispatcherName : the configured Akka dispatcher name to be used for pipe communication within the aggregate actor .
  8. scheduledAsyncEntityActionTimeout : the configured timeout for Async action response waiting to not block the actor forever

Then last point is the Spring configuration to reference your Akka actor system configuration to be used with the toolkit spring boot configuration initialization , can be done like the following :

The configuration need to be prefixed with (spring.akka) , where you need to provide the location if your actor system configuration file and the name of your actor system , In Part 3 we will go through detailed Order manager application sample based into the explained toolkit starter.

// we will see detailed reference for that in part 3 with the working example
spring.akka.config: eventSourcing.conf
spring.akka.system-name: orderManagerSyste

References:

  1. Part 3 :https://mromeh.com/2018/04/27/spring-boot-akka-event-sourcing-starter-part-3-the-working-example/
  2. GitHub Toolkit and Order Manager sample code project URL:  https://github.com/Romeh/spring-boot-akka-event-sourcing-starter
  3. Akka persistence : https://doc.akka.io/docs/akka/2.5/persistence.html
  4. Spring boot : https://projects.spring.io/spring-boot/

 

One comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s