Interface CommandBus

All Superinterfaces:
MessageDispatchInterceptorSupport<CommandMessage<?>>, MessageHandlerInterceptorSupport<CommandMessage<?>>
All Known Implementing Classes:
AsynchronousCommandBus, AxonServerCommandBus, DisruptorCommandBus, DistributedCommandBus, RecordingCommandBus, SimpleCommandBus

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 Details

    • dispatch

      <C> void dispatch(@Nonnull CommandMessage<C> command)
      Dispatch the given 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.
      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 given command's name.
      See Also:
    • dispatch

      <C, R> void dispatch(@Nonnull CommandMessage<C> command, @Nonnull CommandCallback<? super C,? super R> callback)
      Dispatch the given 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.

      Type Parameters:
      C - The payload type of the command to dispatch
      R - The type of the expected result
      Parameters:
      command - The Command to dispatch
      callback - The callback to invoke when command processing is complete
      Throws:
      NoHandlerForCommandException - when no command handler is registered for the given command.
      See Also:
    • subscribe

      Registration subscribe(@Nonnull String commandName, @Nonnull MessageHandler<? super CommandMessage<?>> handler)
      Subscribe the given 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.

      Parameters:
      commandName - The name of the command to subscribe the handler to
      handler - 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.