Interface Configurer

All Superinterfaces:
LifecycleOperations
All Known Implementing Classes:
DefaultConfigurer, SpringConfigurer

public interface Configurer extends LifecycleOperations
Entry point of the Axon Configuration API.

Using DefaultConfigurer.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 configureAggregate(Class) and configure an Event Store (configureEventStore(Function) or configureEmbeddedEventStore(Function)).

Since:
3.0
Author:
Allard Buijze
See Also:
  • Method Details

    • registerEventUpcaster

      Configurer registerEventUpcaster(@Nonnull Function<Configuration,EventUpcaster> upcasterBuilder)
      Registers an upcaster to be used to upcast Events to a newer version
      Parameters:
      upcasterBuilder - The function that returns an EventUpcaster based on the configuration
      Returns:
      the current instance of the Configurer, for chaining purposes
    • configureMessageMonitor

      Configurer configureMessageMonitor(@Nonnull Function<Configuration,BiFunction<Class<?>,String,MessageMonitor<Message<?>>>> messageMonitorFactoryBuilder)
      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. The builder function receives the type of component as well as its name as input, and is expected to return a MessageMonitor instance to be used by that type of component.
      Parameters:
      messageMonitorFactoryBuilder - The MessageMonitor builder function
      Returns:
      the current instance of the Configurer, for chaining purposes
    • configureMessageMonitor

      default Configurer configureMessageMonitor(@Nonnull Class<?> componentType, @Nonnull Function<Configuration,MessageMonitor<Message<?>>> messageMonitorBuilder)
      Configures the builder function 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.

      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.

      Parameters:
      componentType - The declared type of the component
      messageMonitorBuilder - The builder function to use
      Returns:
      the current instance of the Configurer, for chaining purposes
    • configureMessageMonitor

      Configurer configureMessageMonitor(@Nonnull Class<?> componentType, @Nonnull 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.

      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.

      Parameters:
      componentType - The declared type of the component
      messageMonitorFactory - The factory to use
      Returns:
      the current instance of the Configurer, for chaining purposes
    • configureMessageMonitor

      default Configurer configureMessageMonitor(@Nonnull Class<?> componentType, @Nonnull String componentName, @Nonnull Function<Configuration,MessageMonitor<Message<?>>> messageMonitorBuilder)
      Configures the builder function to create the Message Monitor for the Message processing components in this configuration that match the given class and name.

      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.

      Parameters:
      componentType - The declared type of the component
      componentName - The name of the component
      messageMonitorBuilder - The builder function to use
      Returns:
      the current instance of the Configurer, for chaining purposes
    • configureMessageMonitor

      Configurer configureMessageMonitor(@Nonnull Class<?> componentType, @Nonnull String componentName, @Nonnull MessageMonitorFactory messageMonitorFactory)
      Configures the factory create the Message Monitor for those Message processing components in this configuration that match the given class and name.

      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.

      Parameters:
      componentType - The declared type of the component
      componentName - The name of the component
      messageMonitorFactory - The factory to use
      Returns:
      the current instance of the Configurer, for chaining purposes
    • configureCorrelationDataProviders

      Configurer configureCorrelationDataProviders(@Nonnull Function<Configuration,List<CorrelationDataProvider>> correlationDataProviderBuilder)
      Configures the CorrelationDataProviders that Message processing components should use to attach correlation data to outgoing messages. The builder function receives the Configuration as input and is expected to return a list or CorrelationDataProviders.
      Parameters:
      correlationDataProviderBuilder - the builder function returning the CorrelationDataProvider list
      Returns:
      the current instance of the Configurer, for chaining purposes
    • registerModule

      Configurer registerModule(@Nonnull ModuleConfiguration module)
      Registers an Axon module with this configuration. The module is initialized when the configuration is created and has access to the global configuration when initialized.

      Typically, modules are registered for Event Handling components or Sagas.

      Parameters:
      module - The module to register
      Returns:
      the current instance of the Configurer, for chaining purposes
      See Also:
    • registerComponent

      <C> Configurer registerComponent(@Nonnull Class<C> componentType, @Nonnull Function<Configuration,? extends C> componentBuilder)
      Registers a component which should be made available to other components or modules in this Configuration. The builder function gets this configuration as input, and is expected to provide the component as output.

      Where possible, it is recommended to use the explicit configure... and register... methods.

      Type Parameters:
      C - The type of component
      Parameters:
      componentType - The declared type of the component, typically an interface
      componentBuilder - The builder function of this component
      Returns:
      the current instance of the Configurer, for chaining purposes
    • registerCommandHandler

      Configurer registerCommandHandler(@Nonnull Function<Configuration,Object> commandHandlerBuilder)
      Registers a command handler bean with this Configurer. 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.

      Parameters:
      commandHandlerBuilder - the builder function of the command handler bean
      Returns:
      the current instance of the Configurer, for chaining purposes
    • registerCommandHandler

      @Deprecated default Configurer registerCommandHandler(int phase, @Nonnull Function<Configuration,Object> commandHandlerBuilder)
      Deprecated.
      in favor of registerCommandHandler(Function), since the phase of an annotated handler should be defined through the StartHandler/ShutdownHandler annotation.
      Registers a command handler bean with this Configurer. 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.

      Parameters:
      phase - defines a phase in which the command handler builder will be invoked during Configuration.start() and Configuration.shutdown(). When starting the configuration handlers are ordered in ascending, when shutting down the configuration, descending order is used.
      commandHandlerBuilder - the builder function of the command handler bean
      Returns:
      the current instance of the Configurer, for chaining purposes
    • registerQueryHandler

      Configurer registerQueryHandler(@Nonnull Function<Configuration,Object> queryHandlerBuilder)
      Registers a query handler bean with this Configurer. 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.

      Parameters:
      queryHandlerBuilder - the builder function of the query handler bean
      Returns:
      the current instance of the Configurer, for chaining purposes
    • registerQueryHandler

      @Deprecated default Configurer registerQueryHandler(int phase, @Nonnull Function<Configuration,Object> queryHandlerBuilder)
      Deprecated.
      in favor of registerQueryHandler(Function), since the phase of an annotated handler should be defined through the StartHandler/ShutdownHandler annotation.
      Registers a query handler bean with this Configurer. 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.

      Parameters:
      phase - defines a phase in which the query handler builder will be invoked during Configuration.start() and Configuration.shutdown(). When starting the configuration handlers are ordered in ascending, when shutting down the configuration, descending order is used.
      queryHandlerBuilder - the builder function of the query handler bean
      Returns:
      the current instance of the Configurer, for chaining purposes
    • registerMessageHandler

      Configurer registerMessageHandler(@Nonnull Function<Configuration,Object> messageHandlerBuilder)
      Registers a message handler bean with this configuration. The bean may be of any type. The actual message handler methods will be detected based on the annotations present on the bean's methods. Message handling functions annotated with CommandHandler, 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.

      Parameters:
      messageHandlerBuilder - the builder function of the message handler bean
      Returns:
      the current instance of the Configurer, for chaining purposes
    • configureEmbeddedEventStore

      Configurer configureEmbeddedEventStore(@Nonnull Function<Configuration,EventStorageEngine> storageEngineBuilder)
      Configures an Embedded Event Store which uses the given Event Storage Engine to store its events. The builder receives the Configuration as input and is expected to return a fully initialized EventStorageEngine instance.
      Parameters:
      storageEngineBuilder - The builder function for the EventStorageEngine
      Returns:
      the current instance of the Configurer, for chaining purposes
    • configureEventStore

      default Configurer configureEventStore(@Nonnull Function<Configuration,EventStore> eventStoreBuilder)
      Configures the given Event Store to use in this configuration. The builder receives the Configuration as input and is expected to return a fully initialized EventStore instance.
      Parameters:
      eventStoreBuilder - The builder function for the EventStore
      Returns:
      the current instance of the Configurer, for chaining purposes
    • configureEventBus

      default Configurer configureEventBus(@Nonnull Function<Configuration,EventBus> eventBusBuilder)
      Configures the given Event Bus to use in this configuration. The builder receives the Configuration as input and is expected to return a fully initialized EventBus instance.

      Note that this builder should not be used when an Event Store is configured. Since Axon 3, the Event Store will act as Event Bus implementation as well.

      Parameters:
      eventBusBuilder - The builder function for the EventBus
      Returns:
      the current instance of the Configurer, for chaining purposes
    • configureCommandBus

      default Configurer configureCommandBus(@Nonnull Function<Configuration,CommandBus> commandBusBuilder)
      Configures the given Command Bus to use in this configuration. The builder receives the Configuration as input and is expected to return a fully initialized CommandBus instance.
      Parameters:
      commandBusBuilder - The builder function for the CommandBus
      Returns:
      the current instance of the Configurer, for chaining purposes
    • configureQueryBus

      default Configurer configureQueryBus(@Nonnull Function<Configuration,QueryBus> queryBusBuilder)
      Configures the given Query Bus to use in this configuration. The builder receives the Configuration as input and is expected to return a fully initialized QueryBus instance.
      Parameters:
      queryBusBuilder - The builder function for the QueryBus
      Returns:
      the current instance of the Configurer, for chaining purposes
    • configureQueryUpdateEmitter

      default Configurer configureQueryUpdateEmitter(@Nonnull Function<Configuration,QueryUpdateEmitter> queryUpdateEmitterBuilder)
      Configures the given Query Update Emitter to use in this configuration. The builder receives the Configuration as input and is expected to return a fully initialized QueryUpdateEmitter instance.
      Parameters:
      queryUpdateEmitterBuilder - The builder function for the QueryUpdateEmitter
      Returns:
      the current instance of the Configurer, for chaining purposes
    • configureSerializer

      default Configurer configureSerializer(@Nonnull Function<Configuration,Serializer> serializerBuilder)
      Configures the given Serializer to use in this configuration. The builder receives the Configuration as input and is expected to return a fully initialized Serializer instance.
      Parameters:
      serializerBuilder - The builder function for the Serializer
      Returns:
      the current instance of the Configurer, for chaining purposes
    • configureEventSerializer

      Configurer configureEventSerializer(@Nonnull Function<Configuration,Serializer> eventSerializerBuilder)
      Configures the given event Serializer to use in this configuration. The builder receives the Configuration as input and is expected to return a fully initialized Serializer instance.

      This Serializer is specifically used to serialize EventMessage payload and metadata.

      Parameters:
      eventSerializerBuilder - The builder function for the Serializer.
      Returns:
      The current instance of the Configurer, for chaining purposes.
    • configureMessageSerializer

      Configurer configureMessageSerializer(@Nonnull Function<Configuration,Serializer> messageSerializerBuilder)
      Configures the given event Serializer to use in this configuration. The builder receives the Configuration as input and is expected to return a fully initialized Serializer instance.

      This Serializer is specifically used to serialize Message payload and Metadata.

      Parameters:
      messageSerializerBuilder - The builder function for the Serializer.
      Returns:
      The current instance of the Configurer, for chaining purposes.
    • configureTransactionManager

      default Configurer configureTransactionManager(@Nonnull Function<Configuration,TransactionManager> transactionManagerBuilder)
      Configures the given Transaction Manager to use in this configuration. The builder receives the Configuration as input and is expected to return a fully initialized TransactionManager instance.
      Parameters:
      transactionManagerBuilder - The builder function for the TransactionManager
      Returns:
      the current instance of the Configurer, for chaining purposes
    • configureResourceInjector

      default Configurer configureResourceInjector(@Nonnull Function<Configuration,ResourceInjector> resourceInjectorBuilder)
      Configures the given Resource Injector to use for Sagas in this configuration. The builder receives the Configuration as input and is expected to return a fully initialized ResourceInjector instance.
      Parameters:
      resourceInjectorBuilder - The builder function for the ResourceInjector
      Returns:
      the current instance of the Configurer, for chaining purposes
    • configureTags

      default Configurer configureTags(@Nonnull Function<Configuration,TagsConfiguration> tagsBuilder)
      Configures the given Tags Configuration to use in this configuration. The builder receives the Configuration as input and is expected to return a fully initialized TagsConfiguration instance.
      Parameters:
      tagsBuilder - The builder function for the TagsConfiguration
      Returns:
      the current instance of the Configurer, for chaining purposes
    • configureAggregate

      <A> Configurer configureAggregate(@Nonnull AggregateConfiguration<A> aggregateConfiguration)
      Configures an Aggregate in this configuration based on the given aggregateConfiguration. This method allows for more fine-grained configuration compared to the configureAggregate(Class) method.
      Type Parameters:
      A - The type of aggregate the configuration is for
      Parameters:
      aggregateConfiguration - The instance describing the configuration of an Aggregate
      Returns:
      the current instance of the Configurer, for chaining purposes
      See Also:
    • configureAggregate

      default <A> Configurer configureAggregate(@Nonnull Class<A> aggregate)
      Configures an Aggregate using default settings. This means the aggregate is expected to be Event Sourced if an Event Store present in the configuration. Otherwise, an explicit repository must be configured and the configureAggregate(AggregateConfiguration) must be used to register the aggregate.
      Type Parameters:
      A - The type of aggregate
      Parameters:
      aggregate - The aggregate type to register with the Configuration
      Returns:
      the current instance of the Configurer, for chaining purposes
    • registerHandlerDefinition

      Configurer registerHandlerDefinition(@Nonnull BiFunction<Configuration,Class,HandlerDefinition> handlerDefinitionClass)
      Registers the definition of a Handler class. Defaults to annotation based recognition of handler methods.
      Parameters:
      handlerDefinitionClass - A function providing the definition based on the current Configuration as well as the class being inspected.
      Returns:
      the current instance of the Configurer, for chaining purposes
    • registerHandlerEnhancerDefinition

      Configurer registerHandlerEnhancerDefinition(Function<Configuration,HandlerEnhancerDefinition> handlerEnhancerBuilder)
      Registers a builder function for a HandlerEnhancerDefinition 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 registerHandlerDefinition(BiFunction) method's lambda.

      Parameters:
      handlerEnhancerBuilder - A lambda constructing a HandlerEnhancerDefinition based on the Configuration.
      Returns:
      The current instance of the Configurer, for chaining purposes.
    • configureSnapshotter

      default Configurer configureSnapshotter(@Nonnull Function<Configuration,Snapshotter> snapshotterBuilder)
      Registers a Snapshotter instance with this Configurer. Defaults to a AggregateSnapshotter implementation.
      Parameters:
      snapshotterBuilder - the builder function for the Snapshotter
      Returns:
      the current instance of the Configurer, for chaining purposes
    • configureDeadlineManager

      default Configurer configureDeadlineManager(@Nonnull Function<Configuration,DeadlineManager> deadlineManagerBuilder)
      Registers a DeadlineManager instance with this Configurer. Defaults to a SimpleDeadlineManager implementation.
      Parameters:
      deadlineManagerBuilder - a builder function for the DeadlineManager
      Returns:
      the current instance of the Configurer, for chaining purposes
    • configureSpanFactory

      default Configurer configureSpanFactory(@Nonnull Function<Configuration,SpanFactory> spanFactory)
      Registers a SpanFactory instance with this Configurer. Defaults to a NoOpSpanFactory implementation.
      Parameters:
      spanFactory - a builder function for the SpanFactory
      Returns:
      the current instance of the Configurer, for chaining purposes
    • eventProcessing

      Retrieve the EventProcessingConfigurer 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.
      Returns:
      an instance of Event Processing Configurer
      Throws:
      AxonConfigurationException - thrown if there are multiple EventProcessingConfigurers
    • eventProcessing

      default Configurer eventProcessing(@Nonnull Consumer<EventProcessingConfigurer> eventProcessingConfigurer) throws AxonConfigurationException
      Locates the EventProcessingConfigurer registered as a module with this Configurer and provides it to the given consumer for configuration. If there aren't any pre-registered instances of EventProcessingConfigurer, it will create an EventProcessingModule and register it as a module. If there are multiple, an AxonConfigurationException is thrown. This method is identical to using eventProcessing(), except that this variant allows for easier fluent interfacing.
      Parameters:
      eventProcessingConfigurer - a consumer to configure the
      Returns:
      an instance of Event Processing Configurer
      Throws:
      AxonConfigurationException - thrown if there are multiple EventProcessingConfigurers
    • registerEventHandler

      default Configurer registerEventHandler(@Nonnull Function<Configuration,Object> eventHandlerBuilder)
      Registers a Function that builds an Event Handler instance.
      Parameters:
      eventHandlerBuilder - a Function that builds an Event Handler instance.
      Returns:
      the current instance of the Configurer, for chaining purposes.
    • configureLifecyclePhaseTimeout

      default Configurer configureLifecyclePhaseTimeout(long timeout, TimeUnit timeUnit)
      Configures the timeout of each lifecycle phase. The Configurer invokes lifecycle phases during start-up and shutdown of an application.

      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.

      Parameters:
      timeout - the amount of time to wait for lifecycle phase completion
      timeUnit - the unit in which the timeout is expressed
      Returns:
      the current instance of the Configurer, for chaining purposes
      See Also:
    • onInitialize

      default void onInitialize(@Nonnull Consumer<Configuration> initHandler)
      Register an initialization handler which should be invoked prior to starting this Configurer.
      Parameters:
      initHandler - a Consumer of the configuration, to be ran upon initialization of the Configuration
    • buildConfiguration

      Configuration buildConfiguration()
      Returns the completely initialized Configuration built using this configurer. It is not recommended to change any configuration on this Configurer once this method is called.
      Returns:
      the fully initialized Configuration
    • start

      default Configuration start()
      Builds the configuration and starts it immediately. It is not recommended to change any configuration on this Configurer once this method is called.
      Returns:
      The started configuration