axon-spring-boot-starter
dependency, 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 EventStorageEngine
in your Spring Configuration.EventStorageEngine
(to use Event Sourcing) or EventBus
(if Event Sourcing isn't required).SimpleCommandBus
if no CommandBus
implementation is explicitly defined in the Application Context. This CommandBus
will use the TransactionManager
to manage transactions.CommandBus
bean defined is a DistributedCommandBus
implementation, 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 DistributedCommandBus
as a @Primary
, so that it gets priority for dependency injection.SimpleQueryBus
if no QueryBus
implementation is explicitly defined in the Application Context. This QueryBus
will use the TransactionManager
to manage transactions.TransactionManager
implementation is explicitly defined in the Application Content, Axon will look for the Spring PlatformTransactionManager
bean and wrap that in a TransactionManager
. If the Spring bean is not available, the NoOpTransactionManager
will be used.Serializer
in the application context.eventSerializer
qualifier. 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.Serializer
used by your application. The Message Serializer
comes into play when your Command and Query message are sent from one node to another in a distributed environment. To set a custom Serializer
for you message you can simply define a messageSerializer
bean like so:@Aggregate
annotation (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.@CommandHandler
annotated methods with the Command Bus and set up a repository if none is present.SnapshotTriggerDefinition
for an aggregate as a spring bean. In order to tie the SnapshotTriggerDefinition
bean to an aggregate, use the snapshotTriggerDefinition
attribute on @Aggregate
annotation. Listing below shows how to define a custom EventCountSnapshotTriggerDefinition
which will take a snapshot on each 500th event.Snapshotter
instance, if not explicitly defined as a Bean already, will be automatically configured for you. This means you can simply pass the Snapshotter
as a parameter to your SnapshotTriggerDefinition
.CommandTargetResolver
as 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 commandTargetResolver
attribute on @Aggregate
annotation will override this behavior. You can for example define a MetaDataCommandTargetResolver
which will look for myAggregateId
key in meta-data is listed below together with assignment to the aggregate.repository
attribute on @Aggregate
Annotation. 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 EventStore
is available).SnapshotTriggerDefinition
or AggregateFactory
that may otherwise have been configured automatically.@Saga
annotation (in package org.axonframework.spring.stereotype
). Axon will configure a SagaManager
and SagaRepository
. The SagaRepository will use a SagaStore
available in the context (defaulting to JPASagaStore
if JPA is found) for the actual storage of Sagas.SagaStore
s for Sagas, provide the bean name of the SagaStore
to use in the sagaStore
attribute of each @Saga
annotation.@Autowired
and @javax.inject.Inject
annotation 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.SagaConfiguration
with 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.SagaConfiguration
instance 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 SagaConfiguration
using the @Saga annotation:@EventHandler
annotated methods will be subscribed to an Event Processor to receive Event Messages published to the Event Bus.EventHandlingConfiguration
bean, 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.application.properties
..
, use the map notation:SubscribableMessageSource
or StreamableMessageSource
that 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.@QueryHandler
annotation. For each method that is found, a new query handler is registered with the query bus.axon-amqp
module is on the classpath and an AMQP ConnectionFactory
is available in the application context (e.g. by including the spring-boot-starter-amqp
).application.properties
configuration is sufficient:axon.amqp.transaction-mode
property, and setting it to transactional
or publisher-ack
.SpringAMQPMessageSource
:CommandRouter
as well as a CommandBusConnector
are present in the application context. In such case, specifying axon.distributed.enabled
isn't even necessary. The latter merely enables autoconfiguration of these routers and connectors.axon.distributed.jgroups
.@EnableDiscoveryClient
is used and the necessary client is on the classpath).appplication.properties
:SpringCloudHttpBackupCommandRouter
or SpringCloudCommandRouter
bean 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.