Class InterceptingCommandBus
- All Implemented Interfaces:
DescribableComponent,CommandBus,CommandHandlerRegistry<CommandBus>
CommandBus wrapper that supports both MessageHandlerInterceptors and
MessageDispatchInterceptors. Actual dispatching and handling of commands is done
by a delegate.
This InterceptingCommandBus is typically registered as a
decorator and automatically kicks in whenever
CommandMessage specific MessageHandlerInterceptors or any MessageDispatchInterceptors are
present.
- Since:
- 5.0.0
- Author:
- Allad Buijze, Simon Zambrovski, Steven van Beelen
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int -
Constructor Summary
ConstructorsConstructorDescriptionInterceptingCommandBus(CommandBus delegate, List<MessageHandlerInterceptor<? super CommandMessage>> handlerInterceptors, List<MessageDispatchInterceptor<? super CommandMessage>> dispatchInterceptors) Constructs aInterceptingCommandBus, delegating dispatching and handling logic to the givendelegate. -
Method Summary
Modifier and TypeMethodDescriptionvoiddescribeTo(ComponentDescriptor descriptor) Describe the properties ofthis DescribableComponentwith the givendescriptor.dispatch(CommandMessage command, ProcessingContext processingContext) subscribe(QualifiedName name, CommandHandler commandHandler) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.axonframework.messaging.commandhandling.CommandHandlerRegistry
subscribe, subscribe
-
Field Details
-
DECORATION_ORDER
public static final int DECORATION_ORDERThe order in which theInterceptingCommandBusis applied as adecoratorto theCommandBus.As such, any decorator with a lower value will be applied to the delegate, and any higher value will be applied to the
InterceptingCommandBusitself. Using the same value can either lead to application of the decorator to the delegate or theInterceptingCommandBus, depending on the order of registration.The order of the
InterceptingCommandBusis set toInteger.MIN_VALUE + 100to ensure it is applied very early in the configuration process, but not the earliest to allow for other decorators to be applied.- See Also:
-
-
Constructor Details
-
InterceptingCommandBus
public InterceptingCommandBus(@Nonnull CommandBus delegate, @Nonnull List<MessageHandlerInterceptor<? super CommandMessage>> handlerInterceptors, @Nonnull List<MessageDispatchInterceptor<? super CommandMessage>> dispatchInterceptors) Constructs aInterceptingCommandBus, delegating dispatching and handling logic to the givendelegate. The givenhandlerInterceptorsare wrapped around thecommand handlerswhen subscribing. The givendispatchInterceptorsare invoked before dispatching is provided to the givendelegate.- Parameters:
delegate- The delegateCommandBusthat will handle all dispatching and handling logic.handlerInterceptors- The interceptors to invoke before handling a command and if present on the command result.dispatchInterceptors- The interceptors to invoke before dispatching a command and on the command result.
-
-
Method Details
-
subscribe
public InterceptingCommandBus subscribe(@Nonnull QualifiedName name, @Nonnull CommandHandler commandHandler) Description copied from interface:CommandHandlerRegistrySubscribe the givenhandlerforcommandsof the givenname.If a subscription already exists for the
name, the behavior is undefined. Implementations may throw an exception to refuse duplicate subscription or alternatively decide whether the existing or newhandlergets the subscription.- Specified by:
subscribein interfaceCommandHandlerRegistry<CommandBus>- Parameters:
name- The name the givencommandHandlercan handle.commandHandler- The handler instance that handlescommandsfor the given name.- Returns:
- This registry for fluent interfacing.
-
dispatch
public CompletableFuture<CommandResultMessage> dispatch(@Nonnull CommandMessage command, @Nullable ProcessingContext processingContext) Description copied from interface:CommandBusDispatch the givencommandto thecommand handlersubscribedto the givencommand's name. The name is typically deferred from theMessage.type(), which contains aMessageType.qualifiedName().- Specified by:
dispatchin interfaceCommandBus- Parameters:
command- The command to dispatch.processingContext- The processing context under which the command is being published (can benull).- Returns:
- The
CompletableFutureproviding the result of the command, once finished.
-
describeTo
Description copied from interface:DescribableComponentDescribe the properties ofthis DescribableComponentwith the givendescriptor.Components should call the appropriate
describePropertymethods on the descriptor to register their properties. The descriptor is responsible for determining how these properties are formatted and structured in the final output.Best Practices: As a general rule, all relevant fields of a
DescribableComponentimplementation should be described in this method. However, developers have discretion to include only the fields that make sense in the context. Not every field may be meaningful for description purposes, especially internal implementation details. Furthermore, components might want to expose different information based on their current state. The final decision on what properties to include lies with the person implementing thedescribeTomethod, who should focus on providing information that is useful for understanding the component's configuration and state.Example implementation:
public void describeTo(ComponentDescriptor descriptor) { descriptor.describeProperty("name", this.name); descriptor.describeProperty("enabled", this.enabled); descriptor.describeProperty("configuration", this.configuration); // A nested component descriptor.describeProperty("handlers", this.eventHandlers); // A collection }- Specified by:
describeToin interfaceDescribableComponent- Parameters:
descriptor- The component descriptor to describethis DescribableComponentn its properties in.
-