Interface CommandBus
- All Superinterfaces:
MessageDispatchInterceptorSupport<CommandMessage<?>>,MessageHandlerInterceptorSupport<CommandMessage<?>>
- All Known Implementing Classes:
AsynchronousCommandBus,AxonServerCommandBus,DisruptorCommandBus,DistributedCommandBus,RecordingCommandBus,SimpleCommandBus
public interface CommandBus
extends MessageHandlerInterceptorSupport<CommandMessage<?>>, MessageDispatchInterceptorSupport<CommandMessage<?>>
The mechanism that dispatches Command objects to their appropriate CommandHandler. CommandHandlers can subscribe and
unsubscribe to specific commands (identified by their
name) on the command
bus. Only a single handler may be subscribed for a single command name at any time.- Since:
- 0.5
- Author:
- Allard Buijze
-
Method Summary
Modifier and TypeMethodDescription<C> voiddispatch(CommandMessage<C> command) Dispatch the givencommandto the CommandHandler subscribed to the givencommand's name.<C,R> void dispatch(CommandMessage<C> command, CommandCallback<? super C, ? super R> callback) Dispatch the givencommandto the CommandHandler subscribed to the givencommand's name.subscribe(String commandName, MessageHandler<? super CommandMessage<?>> handler) Subscribe the givenhandlerto commands with the givencommandName.Methods inherited from interface org.axonframework.messaging.MessageDispatchInterceptorSupport
registerDispatchInterceptorMethods inherited from interface org.axonframework.messaging.MessageHandlerInterceptorSupport
registerHandlerInterceptor
-
Method Details
-
dispatch
Dispatch the givencommandto the CommandHandler subscribed to the givencommand's name. No feedback is given about the status of the dispatching process. Implementations may return immediately after asserting a valid handler is registered for the given command.- Type Parameters:
C- The payload type of the command to dispatch- Parameters:
command- The Command to dispatch- Throws:
NoHandlerForCommandException- when no command handler is registered for the givencommand's name.- See Also:
-
dispatch
<C,R> void dispatch(@Nonnull CommandMessage<C> command, @Nonnull CommandCallback<? super C, ? super R> callback) Dispatch the givencommandto the CommandHandler subscribed to the givencommand's name. When the command is processed, one of the callback's methods is called, depending on the result of the processing. There are no guarantees about the successful completion of command dispatching or handling after the method returns. Implementations are highly recommended to perform basic validation of the command before returning from this method call. Implementations must start a UnitOfWork when before dispatching the command, and either commit or rollback after a successful or failed execution, respectively.- Type Parameters:
C- The payload type of the command to dispatchR- The type of the expected result- Parameters:
command- The Command to dispatchcallback- The callback to invoke when command processing is complete- Throws:
NoHandlerForCommandException- when no command handler is registered for the givencommand.- See Also:
-
subscribe
Registration subscribe(@Nonnull String commandName, @Nonnull MessageHandler<? super CommandMessage<?>> handler) Subscribe the givenhandlerto commands with the givencommandName. If a subscription already exists for the given name, the behavior is undefined. Implementations may throw an Exception to refuse duplicate subscription or alternatively decide whether the existing or newhandlergets the subscription.- Parameters:
commandName- The name of the command to subscribe the handler tohandler- The handler instance that handles the given type of command- Returns:
- a handle to unsubscribe the
handler. When unsubscribed it will no longer receive commands.
-