axon-spring-boot-starterdependency, Axon will automatically configure the basic infrastructure components (Command Bus, Event Bus), as well as any component required to run and store Aggregates and Sagas.
SimpleEventBus, which means that you need to specify a non-event sourcing repository for each Aggregate, or configure an
EventStorageEnginein your Spring Configuration.
EventStorageEngine(to use Event Sourcing) or
EventBus(if Event Sourcing isn't required).
CommandBusimplementation is explicitly defined in the Application Context. This
CommandBuswill use the
TransactionManagerto manage transactions.
CommandBusbean defined is a
DistributedCommandBusimplementation, Axon will still configure a CommandBus implementation to serve as the local segment for the DistributedCommandBus. This bean will get a Qualifier "localSegment". It is recommended to define the
@Primary, so that it gets priority for dependency injection.
QueryBusimplementation is explicitly defined in the Application Context. This
QueryBuswill use the
TransactionManagerto manage transactions.
TransactionManagerimplementation is explicitly defined in the Application Content, Axon will look for the Spring
PlatformTransactionManagerbean and wrap that in a
TransactionManager. If the Spring bean is not available, the
NoOpTransactionManagerwill be used.
Serializerin the application context.
eventSerializerqualifier. Axon will consider a bean with this qualifier to be the event serializer. If no other bean is defined, Axon will use the default serializer for all other objects to serialize.
Serializerused by your application. The Message
Serializercomes into play when your Command and Query message are sent from one node to another in a distributed environment. To set a custom
Serializerfor you message you can simply define a
messageSerializerbean like so:
@Aggregateannotation (in package
org.axonframework.spring.stereotype) triggers AutoConfiguration to set up the necessary components to use the annotated type as an Aggregate. Note that only the Aggregate Root needs to be annotated.
@CommandHandlerannotated methods with the Command Bus and set up a repository if none is present.
SnapshotTriggerDefinitionfor an aggregate as a spring bean. In order to tie the
SnapshotTriggerDefinitionbean to an aggregate, use the
@Aggregateannotation. Listing below shows how to define a custom
EventCountSnapshotTriggerDefinitionwhich will take a snapshot on each 500th event.
Snapshotterinstance, if not explicitly defined as a Bean already, will be automatically configured for you. This means you can simply pass the
Snapshotteras a parameter to your
CommandTargetResolveras a bean in the Spring Application context will cause that resolver to be used for all aggregate definitions. However, you can also define multiple beans and specify the instance to use with the
@Aggregateannotation will override this behavior. You can for example define a
MetaDataCommandTargetResolverwhich will look for
myAggregateIdkey in meta-data is listed below together with assignment to the aggregate.
@AggregateAnnotation. Alternatively, specify the bean name of the Repository to be the aggregate's name, (first character lowercase), suffixed with
Repository. So on a class of type
MyAggregate, the default Repository name is
myAggregateRepository. If no bean with that name is found, Axon will define an
EventSourcingRepository(which fails if no
AggregateFactorythat may otherwise have been configured automatically.
@Sagaannotation (in package
org.axonframework.spring.stereotype). Axon will configure a
SagaRepository. The SagaRepository will use a
SagaStoreavailable in the context (defaulting to
JPASagaStoreif JPA is found) for the actual storage of Sagas.
SagaStores for Sagas, provide the bean name of the
SagaStoreto use in the
sagaStoreattribute of each
@javax.inject.Injectannotation can be used to demarcate dependencies, but they are injected by Axon by looking for these annotations on Fields and Methods. Constructor injection is not (yet) supported.
SagaConfigurationwith a specific name. For a Saga class called
MySaga, the bean that Axon looks for is
mySagaConfiguration. If no such bean is found, it creates a Configuration based on available components.
SagaConfigurationinstance is present for an annotated Saga, that configuration is used to retrieve and register the components for this type of Saga. If the SagaConfiguration bean is not named as described above, it is possible that the Saga is registered twice, and receives events in duplicate. To prevent this, you can specify the bean name of the
SagaConfigurationusing the @Saga annotation:
@EventHandlerannotated methods will be subscribed to an Event Processor to receive Event Messages published to the Event Bus.
EventHandlingConfigurationbean, available in the Application Context, has methods to tweak the configuration of the Event Handlers. See Configuration API for details on configuring Event Handlers and Event Processors.
., use the map notation:
StreamableMessageSourcethat should be used as the source of events for the mentioned processor. The source default to the Event Bus or Event Store defined in the application context.
@QueryHandlerannotation. For each method that is found, a new query handler is registered with the query bus.
axon-amqpmodule is on the classpath and an AMQP
ConnectionFactoryis available in the application context (e.g. by including the
application.propertiesconfiguration is sufficient:
axon.amqp.transaction-modeproperty, and setting it to
CommandRouteras well as a
CommandBusConnectorare present in the application context. In such case, specifying
axon.distributed.enabledisn't even necessary. The latter merely enables autoconfiguration of these routers and connectors.
@EnableDiscoveryClientis used and the necessary client is on the classpath).
SpringCloudCommandRouterbean in your application context.
NoteIt is regarded as good practice to assign a random value to every service instance name. In doing so, if a given service instance is restarted, it will receive a different name which will mitigate unnecessary blacklisting of nodes.