Executors, meaning that you can easily pass a container managed Thread Pool, for example. If you don't use a full blown Application Server (e.g. Tomcat, Jetty or a stand-alone app), you can use the
Executorsclass or the Spring Framework to create and configure Thread Pools.
RedeemCmd(do note that
amountis amount to be deducted from the Giftcard) and
@TargetAggregateIdentifierannotation is used by Axon to find the correct Giftcard aggregate instance.
Defined commands and events do not have
equals/hashCode/toStringmethods overriden since our example would be lengthy. However, it is highly recommended to do so due to testing/debugging/auditing reasons.
@AggregateIdentifierannotation tells Axon that annotated field will be used as identifier of the Aggregate.
IssueCmdis dispatched, annotated constructor will be invoked.
AggregateLifecycle.applymethod will apply method on given aggregate (
@EventSourcingHandlermatching this event will be called on aggregate), and then it will be published to the
EventBus, so other components can react upon it.
Note All business logic / rules are defined in the
@CommandHandlers, and all state changes are defined in the
@EventSourcingHandlers. The reason for this is when we want to get the current state of event-sourced Aggregate, we have to apply all sourced events - we have to invoke
@EventSourcingHandlers. If the state of our Aggregate is changed outside of
@EventSourcingHandlers it will not be reflected when we do a replay.
ListJava structure as our storage. The
CardSummaryclass could look like this:
EventHandlingConfigurationand as a query handler (4)
Note If you are using Spring, none of these configuration steps are required if you mark