public interface CommandBus extends MessageHandlerInterceptorSupport<CommandMessage<?>>, MessageDispatchInterceptorSupport<CommandMessage<?>>
name
) on the command
bus. Only a single handler may be subscribed for a single command name at any time.Modifier and Type | Method and Description |
---|---|
<C> void |
dispatch(CommandMessage<C> command)
Dispatch the given
command to the CommandHandler subscribed to the given command 's name. |
<C,R> void |
dispatch(CommandMessage<C> command,
CommandCallback<? super C,? super R> callback)
Dispatch the given
command to the CommandHandler subscribed to the given command 's name. |
Registration |
subscribe(String commandName,
MessageHandler<? super CommandMessage<?>> handler)
Subscribe the given
handler to commands with the given commandName . |
registerHandlerInterceptor
registerDispatchInterceptor
<C> void dispatch(@Nonnull CommandMessage<C> command)
command
to the CommandHandler subscribed to the given command
'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.C
- The payload type of the command to dispatchcommand
- The Command to dispatchNoHandlerForCommandException
- when no command handler is registered for the given command
's name.GenericCommandMessage.asCommandMessage(Object)
<C,R> void dispatch(@Nonnull CommandMessage<C> command, @Nonnull CommandCallback<? super C,? super R> callback)
command
to the CommandHandler subscribed to the given command
'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.C
- The payload type of the command to dispatchR
- The type of the expected resultcommand
- The Command to dispatchcallback
- The callback to invoke when command processing is completeNoHandlerForCommandException
- when no command handler is registered for the given command
.GenericCommandMessage.asCommandMessage(Object)
Registration subscribe(@Nonnull String commandName, @Nonnull MessageHandler<? super CommandMessage<?>> handler)
handler
to commands with the given commandName
.
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 new handler
gets the subscription.commandName
- The name of the command to subscribe the handler tohandler
- The handler instance that handles the given type of commandhandler
. When unsubscribed it will no longer receive commands.Copyright © 2010–2024. All rights reserved.