Now we will continue in part 2 to explain the starter itself into more details :
The Tookit Starter Is An Abstraction For The Following :
- How to define persistent entity actors for your aggregate plus the integration with spring
- 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
- Cluster sharding abstraction for your created persistent entities plus make it configurable via spring
- 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 :
then the actions will be generated from flow command handlers or event handlers based into the class diagram above are :
- Persist one generated event then do post action if any
- Persist list of generated events then do post action if any
- No generated events to persist and just do post action if any (read only commands case)
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
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 :
- snspshotStateAfter property is to snapshot the state after specific configured periodic time
- entityPassivateAfter to passivate the entity actor after configured time
- tags is the event tags used to tag events before storing them into the event store
- numberOfshards : configuration of the number of cluster shards for this entity
- persistentIdPostfix and PersistenceIdProfix : used for the unique aggregate Id within the shard .
- asyncPersistentEntityDispatcherName : the name of the configure Akka dispatcher to be use for the Async actions within the aggregate actor
- pipeDispatcherName : the configured Akka dispatcher name to be used for pipe communication within the aggregate actor .
- 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
- Part 3 :https://mromeh.com/2018/04/27/spring-boot-akka-event-sourcing-starter-part-3-the-working-example/
- GitHub Toolkit and Order Manager sample code project URL: https://github.com/Romeh/spring-boot-akka-event-sourcing-starter
- Akka persistence : https://doc.akka.io/docs/akka/2.5/persistence.html
- Spring boot : https://projects.spring.io/spring-boot/