Interface CommandHandlingModule.CommandHandlerPhase
- All Superinterfaces:
ModuleBuilder<CommandHandlingModule>
- Enclosing interface:
CommandHandlingModule
Every registered CommandHandler will be subscribed with the CommandBus of the
ApplicationConfigurer this module is given to.
Provides roughly two options for configuring command handlers. Firstly, a command handler can be registered as
is, through the commandHandler(QualifiedName, CommandHandler) method. Secondly, if the command handler
provides components from the Configuration, a builder of the command handler can
be registered through the commandHandler(QualifiedName, ComponentBuilder) method.
-
Method Summary
Modifier and TypeMethodDescriptionautodetectedCommandHandlingComponent(ComponentBuilder<Object> handlingComponentBuilder) Registers the givenhandlingComponentBuilderas anAnnotatedCommandHandlingComponentwithin this module.commandHandler(QualifiedName commandName, ComponentBuilder<CommandHandler> commandHandlerBuilder) Registers the givencommandHandlerBuilderfor the given qualifiedcommandNamewithin this module.commandHandler(QualifiedName commandName, CommandHandler commandHandler) Registers the givencommandHandlerfor the given qualifiedcommandNamewithin this module.commandHandlingComponent(ComponentBuilder<CommandHandlingComponent> handlingComponentBuilder) Registers the givenhandlingComponentBuilderwithin this module.intercepted(ComponentBuilder<MessageHandlerInterceptor<? super CommandMessage>> interceptorBuilder) Registers an interceptor to be applied to the command handling component assembled by this module.withExceptionHandler(ComponentBuilder<? extends MessageHandlingExceptionHandler<? super CommandMessage>> handlerBuilder) Wraps the command handling component with the exception handler built by the givenhandlerBuilder.Methods inherited from interface org.axonframework.common.configuration.ModuleBuilder
build
-
Method Details
-
commandHandler
default CommandHandlingModule.CommandHandlerPhase commandHandler(QualifiedName commandName, CommandHandler commandHandler) Registers the givencommandHandlerfor the given qualifiedcommandNamewithin this module.Use this command handler registration method when the command handler in question does not require entities or receives entities through another mechanism. Using a
MessageTypeResolverto derive thecommandNameis beneficial to ensure consistent naming across handler subscriptions.Once this module is finalized, the command handler will be subscribed with the
CommandBusof theApplicationConfigurerthe module is registered on.- Parameters:
commandName- The qualified name of the command the givencommandHandlercan handle.commandHandler- The command handler to register with this module.- Returns:
- The command handler phase of this builder, for a fluent API.
-
commandHandler
CommandHandlingModule.CommandHandlerPhase commandHandler(QualifiedName commandName, ComponentBuilder<CommandHandler> commandHandlerBuilder) Registers the givencommandHandlerBuilderfor the given qualifiedcommandNamewithin this module.Using a
MessageTypeResolverto derive thecommandNameis beneficial to ensure consistent naming across handler subscriptions.Once this module is finalized, the command handler from the
commandHandlerBuilderwill be subscribed with theCommandBusof theApplicationConfigurerthe module is registered on.- Parameters:
commandName- The qualified name of the command theCommandHandlercreated by the givencommandHandlerBuilder.commandHandlerBuilder- A builder of aCommandHandler. Provides theConfigurationto retrieve components from to use during construction of the command handler.- Returns:
- The command handler phase of this builder, for a fluent API.
-
commandHandlingComponent
CommandHandlingModule.CommandHandlerPhase commandHandlingComponent(ComponentBuilder<CommandHandlingComponent> handlingComponentBuilder) Registers the givenhandlingComponentBuilderwithin this module.Use this command handler registration method when the command handling component in question does not require entities or receives entities through another mechanism.
Once this module is finalized, the resulting
CommandHandlingComponentfrom thehandlingComponentBuilderwill be subscribed with theCommandBusof theApplicationConfigurerthe module is registered on.- Parameters:
handlingComponentBuilder- A builder of aCommandHandlingComponent. Provides theConfigurationto retrieve components from to use during construction of the command handling component.- Returns:
- The command handler phase of this builder, for a fluent API.
-
intercepted
CommandHandlingModule.CommandHandlerPhase intercepted(ComponentBuilder<MessageHandlerInterceptor<? super CommandMessage>> interceptorBuilder) Registers an interceptor to be applied to the command handling component assembled by this module. Multiple calls accumulate interceptors in registration order.- Parameters:
interceptorBuilder- builder for the interceptor to apply- Returns:
- the command handler phase of this builder, for a fluent API
-
autodetectedCommandHandlingComponent
default CommandHandlingModule.CommandHandlerPhase autodetectedCommandHandlingComponent(ComponentBuilder<Object> handlingComponentBuilder) Registers the givenhandlingComponentBuilderas anAnnotatedCommandHandlingComponentwithin this module.This will scan the given
handlingComponentBuilderfor methods annotated withCommandHandlerand register them as command handlers for theCommandBusof theApplicationConfigurer.- Parameters:
handlingComponentBuilder- A builder of aCommandHandlingComponent. Provides theConfigurationto retrieve components from to use during construction of the command handling component.- Returns:
- The command handler phase of this builder, for a fluent API.
-
withExceptionHandler
default CommandHandlingModule.CommandHandlerPhase withExceptionHandler(ComponentBuilder<? extends MessageHandlingExceptionHandler<? super CommandMessage>> handlerBuilder) Wraps the command handling component with the exception handler built by the givenhandlerBuilder. When a command handler throws, the exception handler is invoked. ReturnMessageStream.empty()to suppress the error,MessageStream.failed(Throwable)to propagate it, or a stream with aCommandResultMessageto substitute a result.Accepts either a
CommandHandlingExceptionHandler(which narrows the return type for substituting aCommandResultMessage) or a genericMessageHandlingExceptionHandlertyped at any supertype ofCommandMessage, allowing a single handler implementation (such as a logger) to be reused across command, event, and query phases.Multiple calls accumulate handlers; later-registered handlers are applied closer to the handler and see exceptions first.
- Parameters:
handlerBuilder- builder for the exception handler to apply to the command handling component- Returns:
- this phase for further configuration
-