public class DefaultConfigurer extends Object implements Configurer
Using defaultConfiguration(), you will get a Configurer instance with default components configured. You
will need to register your Aggregates (using configureAggregate(AggregateConfiguration) and provide a
repository implementation for each of them, or if you wish to use event sourcing, register your aggregates through
Configurer.configureAggregate(Class) and configure an Event Store (Configurer.configureEventStore(Function) or
configureEmbeddedEventStore(Function)).
Use buildConfiguration() to build the configuration, which provides access to the configured building
blocks, such as the CommandBus and EventBus.
Note that this Configurer implementation is not thread-safe.
| Modifier | Constructor and Description |
|---|---|
protected |
DefaultConfigurer()
Initialize the Configurer.
|
| Modifier and Type | Method and Description |
|---|---|
Configuration |
buildConfiguration()
Returns the completely initialized Configuration built using this configurer.
|
<A> Configurer |
configureAggregate(AggregateConfiguration<A> aggregateConfiguration)
Configures an Aggregate in this configuration based on the given
aggregateConfiguration. |
Configurer |
configureCorrelationDataProviders(Function<Configuration,List<CorrelationDataProvider>> correlationDataProviderBuilder)
Configures the CorrelationDataProviders that Message processing components should use to attach correlation data
to outgoing messages.
|
Configurer |
configureEmbeddedEventStore(Function<Configuration,EventStorageEngine> storageEngineBuilder)
Configures an Embedded Event Store which uses the given Event Storage Engine to store its events.
|
Configurer |
configureEventSerializer(Function<Configuration,Serializer> eventSerializerBuilder)
Configures the given event Serializer to use in this configuration.
|
Configurer |
configureLifecyclePhaseTimeout(long timeout,
TimeUnit timeUnit)
Configures the timeout of each lifecycle phase.
|
Configurer |
configureMessageMonitor(Class<?> componentType,
MessageMonitorFactory messageMonitorFactory)
Configures the factory to create the Message Monitor for the Message processing components in this configuration
that match the given componentType, unless more specific configuration based on both type and name is available.
|
Configurer |
configureMessageMonitor(Class<?> componentType,
String componentName,
MessageMonitorFactory messageMonitorFactory)
Configures the factory create the Message Monitor for those Message processing components in this configuration
that match the given class and name.
|
Configurer |
configureMessageMonitor(Function<Configuration,BiFunction<Class<?>,String,MessageMonitor<Message<?>>>> builder)
Configures the Message Monitor to use for the Message processing components in this configuration, unless more
specific configuration based on the component's type, or type and name is available.
|
Configurer |
configureMessageSerializer(Function<Configuration,Serializer> messageSerializerBuilder)
Configures the given event Serializer to use in this configuration.
|
protected CommandBus |
defaultCommandBus(Configuration config)
Provides the default CommandBus implementation.
|
protected CommandGateway |
defaultCommandGateway(Configuration config)
Returns a
DefaultCommandGateway that will use the configuration's CommandBus to dispatch
commands. |
protected <T> Optional<T> |
defaultComponent(Class<T> type,
Configuration configuration)
Method returning a default component to use for given
type for given configuration, or an empty
Optional if no default can be provided. |
static Configurer |
defaultConfiguration()
Returns a Configurer instance with default components configured, such as a
SimpleCommandBus and
SimpleEventBus. |
static Configurer |
defaultConfiguration(boolean autoLocateConfigurerModules)
Returns a Configurer instance with default components configured, such as a
SimpleCommandBus and
SimpleEventBus, indicating whether to autoLocateConfigurerModules. |
protected DeadlineManager |
defaultDeadlineManager(Configuration config)
Provides the default
DeadlineManager implementation. |
protected EventBus |
defaultEventBus(Configuration config)
Provides the default EventBus implementation.
|
protected EventGateway |
defaultEventGateway(Configuration config)
Returns a
DefaultEventGateway that will use the configuration's EventBus to publish events. |
protected HandlerDefinition |
defaultHandlerDefinition(Class<?> inspectedClass)
Provides the default HandlerDefinition.
|
protected ParameterResolverFactory |
defaultParameterResolverFactory(Configuration config)
Provides the default ParameterResolverFactory.
|
protected QueryBus |
defaultQueryBus(Configuration config)
Provides the default QueryBus implementations.
|
protected QueryGateway |
defaultQueryGateway(Configuration config)
Returns a
DefaultQueryGateway that will use the configuration's QueryBus to dispatch queries. |
protected QueryUpdateEmitter |
defaultQueryUpdateEmitter(Configuration config)
Provides the default QueryUpdateEmitter implementation.
|
protected ResourceInjector |
defaultResourceInjector(Configuration config)
Returns a
ConfigurationResourceInjector that injects resources defined in the given
config Configuration. |
protected ScopeAwareProvider |
defaultScopeAwareProvider(Configuration config)
|
protected Serializer |
defaultSerializer(Configuration config)
Provides the default Serializer implementation.
|
protected Snapshotter |
defaultSnapshotter(Configuration config)
Provides the default
Snapshotter implementation, defaulting to a AggregateSnapshotter. |
protected SpanFactory |
defaultSpanFactory(Configuration config)
Returns the default
SpanFactory, or a NoOpSpanFactory if none it set. |
protected EventUpcasterChain |
defaultUpcasterChain(Configuration config)
Provides the default
EventUpcasterChain implementation, looping through all
registered EventUpcasters to collect them for a
fresh EventUpcasterChain. |
EventProcessingConfigurer |
eventProcessing()
Retrieve the
EventProcessingConfigurer registered as a module with this Configurer. |
Map<Class<?>,Component<?>> |
getComponents()
Returns a map of all registered components in this configuration.
|
protected Configuration |
getConfig()
Returns the current Configuration object being built by this Configurer, without initializing it.
|
protected void |
invokeInitHandlers()
Calls all registered init handlers.
|
protected void |
invokeShutdownHandlers()
Invokes all registered shutdown handlers.
|
protected void |
invokeStartHandlers()
Invokes all registered start handlers.
|
static Configurer |
jpaConfiguration(EntityManagerProvider entityManagerProvider)
Returns a Configurer instance which has JPA versions of building blocks configured, such as a JPA based Event
Store (see
JpaEventStorageEngine), a JpaTokenStore and JpaSagaStore. |
static Configurer |
jpaConfiguration(EntityManagerProvider entityManagerProvider,
TransactionManager transactionManager)
Returns a Configurer instance which has JPA versions of building blocks configured, such as a JPA based Event
Store (see
JpaEventStorageEngine), a JpaTokenStore and JpaSagaStore. |
void |
onShutdown(int phase,
LifecycleHandler shutdownHandler)
Registers an asynchronous
shutdownHandler to be executed in the given phase when the
Configuration is shut down. |
void |
onStart(int phase,
LifecycleHandler startHandler)
Registers an asynchronous
startHandler to be executed in the given phase when this Configuration
is started. |
protected void |
prepareMessageHandlerRegistrars()
Prepare the registered message handlers
MessageHandlerRegistrar for initialization. |
protected void |
prepareModules()
Prepare the registered modules for initialization.
|
Configurer |
registerCommandHandler(Function<Configuration,Object> commandHandlerBuilder)
Registers a command handler bean with this
Configurer. |
<C> Configurer |
registerComponent(Class<C> componentType,
Function<Configuration,? extends C> componentBuilder)
Registers a component which should be made available to other components or modules in this Configuration.
|
Configurer |
registerEventUpcaster(Function<Configuration,EventUpcaster> upcasterBuilder)
Registers an upcaster to be used to upcast Events to a newer version
|
Configurer |
registerHandlerDefinition(BiFunction<Configuration,Class,HandlerDefinition> handlerDefinitionClass)
Registers the definition of a Handler class.
|
Configurer |
registerHandlerEnhancerDefinition(Function<Configuration,HandlerEnhancerDefinition> handlerEnhancerBuilder)
Registers a builder function for a
HandlerEnhancerDefinition used during constructing of the default
HandlerDefinition. |
Configurer |
registerMessageHandler(Function<Configuration,Object> messageHandlerBuilder)
Registers a message handler bean with this configuration.
|
Configurer |
registerModule(ModuleConfiguration module)
Registers an Axon module with this configuration.
|
Configurer |
registerQueryHandler(Function<Configuration,Object> queryHandlerBuilder)
Registers a query handler bean with this
Configurer. |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitconfigureAggregate, configureCommandBus, configureDeadlineManager, configureEventBus, configureEventStore, configureMessageMonitor, configureMessageMonitor, configureQueryBus, configureQueryUpdateEmitter, configureResourceInjector, configureSerializer, configureSnapshotter, configureSpanFactory, configureTags, configureTransactionManager, eventProcessing, onInitialize, registerCommandHandler, registerEventHandler, registerQueryHandler, startonShutdown, onShutdown, onStart, onStartpublic static Configurer defaultConfiguration()
SimpleCommandBus and
SimpleEventBus.public static Configurer defaultConfiguration(boolean autoLocateConfigurerModules)
SimpleCommandBus and
SimpleEventBus, indicating whether to autoLocateConfigurerModules.
When autoLocateConfigurerModules is true, a ServiceLoader will be used to locate all declared
instances of type ConfigurerModule. Each of the discovered instances will be invoked, allowing it to set
default values for the configuration.
autoLocateConfigurerModules - flag indicating whether ConfigurerModules on the classpath should be
automatically retrieved. Should be set to false when using an
application container, such as Spring or CDI.public static Configurer jpaConfiguration(EntityManagerProvider entityManagerProvider, TransactionManager transactionManager)
JpaEventStorageEngine), a JpaTokenStore and JpaSagaStore.
entityManagerProvider - The instance that provides access to the JPA EntityManager.transactionManager - TransactionManager to be used for accessing the entity manager.public static Configurer jpaConfiguration(EntityManagerProvider entityManagerProvider)
JpaEventStorageEngine), a JpaTokenStore and JpaSagaStore.
TransactionManager in the
jpaConfiguration(EntityManagerProvider, TransactionManager) method.entityManagerProvider - The instance that provides access to the JPA EntityManager.protected <T> Optional<T> defaultComponent(Class<T> type, Configuration configuration)
type for given configuration, or an empty
Optional if no default can be provided.T - The type of component.type - The type of component to find a default for.configuration - The configuration the component is configured in.protected CommandGateway defaultCommandGateway(Configuration config)
DefaultCommandGateway that will use the configuration's CommandBus to dispatch
commands.config - The configuration that supplies the command bus.protected QueryGateway defaultQueryGateway(Configuration config)
DefaultQueryGateway that will use the configuration's QueryBus to dispatch queries.config - The configuration that supplies the query bus.protected QueryBus defaultQueryBus(Configuration config)
config - The configuration based on which the component is initialized.protected QueryUpdateEmitter defaultQueryUpdateEmitter(Configuration config)
config - The configuration based on which the component is initializedprotected ParameterResolverFactory defaultParameterResolverFactory(Configuration config)
config - The configuration based on which the component is initialized.protected HandlerDefinition defaultHandlerDefinition(Class<?> inspectedClass)
inspectedClass - The class being inspected for handlersprotected CommandBus defaultCommandBus(Configuration config)
config - The configuration based on which the component is initialized.protected ResourceInjector defaultResourceInjector(Configuration config)
ConfigurationResourceInjector that injects resources defined in the given
config Configuration.config - The configuration that supplies registered components.protected ScopeAwareProvider defaultScopeAwareProvider(Configuration config)
ScopeAwareProvider that provides ScopeAware instances to be
used by a DeadlineManager. Uses the given config to construct the default
ConfigurationScopeAwareProvider.config - the configuration used to construct the default ConfigurationScopeAwareProviderScopeAwareProvider that provides ScopeAware instances to be
used by a DeadlineManagerprotected DeadlineManager defaultDeadlineManager(Configuration config)
DeadlineManager implementation. Subclasses may override this method to provide their
own default.config - The configuration that supplies registered components.protected EventBus defaultEventBus(Configuration config)
config - The configuration based on which the component is initialized.protected EventGateway defaultEventGateway(Configuration config)
DefaultEventGateway that will use the configuration's EventBus to publish events.config - The configuration that supplies the event bus.protected SpanFactory defaultSpanFactory(Configuration config)
SpanFactory, or a NoOpSpanFactory if none it set.config - The configuration that supplies the span factory.SpanFactory.protected Serializer defaultSerializer(Configuration config)
config - The configuration based on which the component is initialized.protected EventUpcasterChain defaultUpcasterChain(Configuration config)
EventUpcasterChain implementation, looping through all
registered EventUpcasters to collect them for a
fresh EventUpcasterChain. Subclasses may override this method to provide their own default.config - The configuration based on which the component is initialized.protected Snapshotter defaultSnapshotter(Configuration config)
Snapshotter implementation, defaulting to a AggregateSnapshotter. Subclasses
may override this method to provide their own default.config - the configuration based on which the Snapshotter will be initializedSnapshotterpublic EventProcessingConfigurer eventProcessing()
ConfigurerEventProcessingConfigurer registered as a module with this Configurer. If there aren't
any, it will create an EventProcessingModule and register it as a module. If there are multiple,
an AxonConfigurationException is thrown.eventProcessing in interface Configurerpublic Configurer registerEventUpcaster(@Nonnull Function<Configuration,EventUpcaster> upcasterBuilder)
ConfigurerregisterEventUpcaster in interface ConfigurerupcasterBuilder - The function that returns an EventUpcaster based on the configurationpublic Configurer configureMessageMonitor(@Nonnull Function<Configuration,BiFunction<Class<?>,String,MessageMonitor<Message<?>>>> builder)
ConfigurerconfigureMessageMonitor in interface Configurerbuilder - The MessageMonitor builder functionpublic Configurer configureMessageMonitor(@Nonnull Class<?> componentType, @Nonnull MessageMonitorFactory messageMonitorFactory)
Configurer
A component matches componentType if componentType is assignable from the component's class. If a component matches multiple types, and the types derive from each other, the configuration from the most derived type is used. If the matching types do not derive from each other, the result is unspecified.
For example: in case a monitor is configured for CommandBus and another monitor is configured for
SimpleCommandBus), components of type
AsynchronousCommandBus will use the monitor
configured for the SimpleCommandBus.
A component's name matches componentName if they are identical; i.e. they are compared case sensitively.
configureMessageMonitor in interface ConfigurercomponentType - The declared type of the componentmessageMonitorFactory - The factory to usepublic Configurer configureMessageMonitor(@Nonnull Class<?> componentType, @Nonnull String componentName, @Nonnull MessageMonitorFactory messageMonitorFactory)
Configurer
A component matches componentType if componentType is assignable from the component's class. If a component matches multiple types, and the types derive from each other, the configuration from the most derived type is used. If the matching types do not derive from each other, the result is unspecified.
For example: in case a monitor is configured for CommandBus and another monitor is configured for
SimpleCommandBus), components of type
AsynchronousCommandBus will use the monitor
configured for the SimpleCommandBus.
A component's name matches componentName if they are identical; i.e. they are compared case sensitively.
configureMessageMonitor in interface ConfigurercomponentType - The declared type of the componentcomponentName - The name of the componentmessageMonitorFactory - The factory to usepublic Configurer configureCorrelationDataProviders(@Nonnull Function<Configuration,List<CorrelationDataProvider>> correlationDataProviderBuilder)
ConfigurerconfigureCorrelationDataProviders in interface ConfigurercorrelationDataProviderBuilder - the builder function returning the CorrelationDataProvider listpublic Configurer registerModule(@Nonnull ModuleConfiguration module)
ConfigurerTypically, modules are registered for Event Handling components or Sagas.
registerModule in interface Configurermodule - The module to registerSagaConfigurationpublic <C> Configurer registerComponent(@Nonnull Class<C> componentType, @Nonnull Function<Configuration,? extends C> componentBuilder)
Configurer
Where possible, it is recommended to use the explicit configure... and register... methods.
registerComponent in interface ConfigurerC - The type of componentcomponentType - The declared type of the component, typically an interfacecomponentBuilder - The builder function of this componentpublic Configurer registerCommandHandler(@Nonnull Function<Configuration,Object> commandHandlerBuilder)
ConfigurerConfigurer. The bean may be of any type. The actual command
handler methods will be detected based on the annotations present on the bean's methods. Message handling
functions annotated with CommandHandler will be taken into account.
The builder function receives the Configuration as input, and is expected to return a fully initialized
instance of the command handler bean.
registerCommandHandler in interface ConfigurercommandHandlerBuilder - the builder function of the command handler beanConfigurer, for chaining purposespublic Configurer registerQueryHandler(@Nonnull Function<Configuration,Object> queryHandlerBuilder)
ConfigurerConfigurer. The bean may be of any type. The actual query
handler methods will be detected based on the annotations present on the bean's methods. Message handling
functions annotated with QueryHandler will be taken into account.
The builder function receives the Configuration as input, and is expected to return a fully initialized
instance of the query handler bean.
registerQueryHandler in interface ConfigurerqueryHandlerBuilder - the builder function of the query handler beanConfigurer, for chaining purposespublic Configurer registerMessageHandler(@Nonnull Function<Configuration,Object> messageHandlerBuilder)
ConfigurerCommandHandler, EventHandler and QueryHandler will be
taken into account.
The builder function receives the Configuration as input, and is expected to return a fully initialized
instance of the message handler bean.
registerMessageHandler in interface ConfigurermessageHandlerBuilder - the builder function of the message handler beanConfigurer, for chaining purposespublic Configurer configureEmbeddedEventStore(@Nonnull Function<Configuration,EventStorageEngine> storageEngineBuilder)
ConfigurerEventStorageEngine
instance.configureEmbeddedEventStore in interface ConfigurerstorageEngineBuilder - The builder function for the EventStorageEnginepublic Configurer configureEventSerializer(@Nonnull Function<Configuration,Serializer> eventSerializerBuilder)
ConfigurerSerializer instance.
This Serializer is specifically used to serialize EventMessage payload and metadata.configureEventSerializer in interface ConfigurereventSerializerBuilder - The builder function for the Serializer.public Configurer configureMessageSerializer(@Nonnull Function<Configuration,Serializer> messageSerializerBuilder)
ConfigurerSerializer instance.
This Serializer is specifically used to serialize Message payload and Metadata.configureMessageSerializer in interface ConfigurermessageSerializerBuilder - The builder function for the Serializer.public <A> Configurer configureAggregate(@Nonnull AggregateConfiguration<A> aggregateConfiguration)
ConfigureraggregateConfiguration. This method
allows for more fine-grained configuration compared to the Configurer.configureAggregate(Class) method.configureAggregate in interface ConfigurerA - The type of aggregate the configuration is foraggregateConfiguration - The instance describing the configuration of an AggregateAggregateConfigurerpublic Configurer registerHandlerDefinition(@Nonnull BiFunction<Configuration,Class,HandlerDefinition> handlerDefinitionClass)
ConfigurerregisterHandlerDefinition in interface ConfigurerhandlerDefinitionClass - A function providing the definition based on the current Configuration as well
as the class being inspected.public Configurer registerHandlerEnhancerDefinition(Function<Configuration,HandlerEnhancerDefinition> handlerEnhancerBuilder)
ConfigurerHandlerEnhancerDefinition used during constructing of the default
HandlerDefinition.
Any number of handler enhancer builder functions can be registered through this method. Note that any
HandlerEnhancerDefinitions registered through this method are ignored for handlers matching the
type used in the Configurer.registerHandlerDefinition(BiFunction) method's lambda.
registerHandlerEnhancerDefinition in interface ConfigurerhandlerEnhancerBuilder - A lambda constructing a HandlerEnhancerDefinition based on the
Configuration.Configurer, for chaining purposes.public Configurer configureLifecyclePhaseTimeout(long timeout, TimeUnit timeUnit)
Configurer
Note that if a lifecycle phase exceeds the configured timeout and timeUnit combination, the
Configurer will proceed with the following phase. A phase-skip is marked with a warn logging message, as the
chances are high this causes undesired side effects.
The default lifecycle phase timeout is five seconds.
configureLifecyclePhaseTimeout in interface Configurertimeout - the amount of time to wait for lifecycle phase completiontimeUnit - the unit in which the timeout is expressedPhase,
LifecycleHandlerpublic Configuration buildConfiguration()
ConfigurerbuildConfiguration in interface Configurerprotected void prepareModules()
protected void prepareMessageHandlerRegistrars()
MessageHandlerRegistrar for initialization. This ensures their
lifecycle handlers are registered.protected void invokeInitHandlers()
protected void invokeStartHandlers()
protected void invokeShutdownHandlers()
protected Configuration getConfig()
public Map<Class<?>,Component<?>> getComponents()
Component.get() may prematurely initialize a component.public void onStart(int phase,
LifecycleHandler startHandler)
LifecycleOperationsstartHandler to be executed in the given phase when this Configuration
is started.
The behavior for handlers that are registered when the Configuration is already started is undefined.
onStart in interface LifecycleOperationsphase - defines a phase in which the start handler will be invoked during Configuration.start(). When starting the configuration the given handlers are started in
ascending order based on their phasestartHandler - the handler to be executed asynchronously when the configuration is startedConfiguration.start()public void onShutdown(int phase,
LifecycleHandler shutdownHandler)
LifecycleOperationsshutdownHandler to be executed in the given phase when the
Configuration is shut down.
The behavior for handlers that are registered when the Configuration is already shut down is undefined.
onShutdown in interface LifecycleOperationsphase - defines a phase in which the shutdown handler will be invoked during Configuration.shutdown(). When shutting down the configuration the given handlers are
executing in descending order based on their phaseshutdownHandler - the handler to be executed asynchronously when the Configuration is shut downConfiguration.shutdown()Copyright © 2010–2023. All rights reserved.