Class ContextAwareCommandDispatcher

java.lang.Object
org.axonframework.messaging.commandhandling.gateway.ContextAwareCommandDispatcher
All Implemented Interfaces:
DescribableComponent, CommandDispatcher

@Internal public class ContextAwareCommandDispatcher extends Object implements CommandDispatcher
A CommandDispatcher that publishes commands to a CommandGateway in a predefined ProcessingContext.

Any commands dispatched through this CommandDispatcher occur within the context this dispatcher was created with. You can construct one through the

invalid reference
CommandDispatcher#forContext(ProcessingContext, Configuration)
method.
Since:
5.0.0
Author:
Steven van Beelen
  • Method Details

    • send

      public CommandResult send(@Nonnull Object command)
      Description copied from interface: CommandDispatcher
      Sends the given command and returns a CommandResult immediately, without waiting for the command to execute.

      The caller will therefore not receive any immediate feedback on the command's execution. Instead, hooks can be added to the returned CommandResult to react on success or failure of command execution. A shorthand to retrieve a CompletableFuture is available through the CommandResult.getResultMessage() operation.

      Note that this operation expects the CommandBus to use new threads for command execution.

      The given command is wrapped as the payload of the CommandMessage that is eventually posted on the CommandBus, unless the command already implements Message. In that case, a CommandMessage is constructed from that message's payload and Metadata.

      Specified by:
      send in interface CommandDispatcher
      Parameters:
      command - The command payload or CommandMessage to send.
      Returns:
      A command result success and failure hooks can be registered. The CommandResult.getResultMessage() serves as a shorthand to retrieve the response.
    • send

      public CommandResult send(@Nonnull Object command, @Nonnull Metadata metadata)
      Description copied from interface: CommandDispatcher
      Sends the given command with the given metadata and returns a CommandResult immediately, without waiting for the command to execute.

      The caller will therefore not receive any immediate feedback on the command's execution. Instead, hooks can be added to the returned CommandResult to react on success or failure of command execution. A shorthand to retrieve a CompletableFuture is available through the CommandResult.getResultMessage() operation.

      Note that this operation expects the CommandBus to use new threads for command execution.

      The given command and metadata are wrapped as the payload of the CommandMessage that is eventually posted on the CommandBus, unless the command already implements Message. In that case, a CommandMessage is constructed from that message's payload and Metadata. The provided metadata is attached afterward in this case.

      Specified by:
      send in interface CommandDispatcher
      Parameters:
      command - The command payload or CommandMessage to send.
      metadata - Metadata that must be registered with the command.
      Returns:
      A command result success and failure hooks can be registered. The CommandResult.getResultMessage() serves as a shorthand to retrieve the response.
    • describeTo

      public void describeTo(@Nonnull ComponentDescriptor descriptor)
      Description copied from interface: DescribableComponent
      Describe the properties of this DescribableComponent with the given descriptor.

      Components should call the appropriate describeProperty methods 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 DescribableComponent implementation 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 the describeTo method, 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:
      describeTo in interface DescribableComponent
      Parameters:
      descriptor - The component descriptor to describe this DescribableComponentn its properties in.