Class DefaultCommandGateway

java.lang.Object
org.axonframework.messaging.commandhandling.gateway.DefaultCommandGateway
All Implemented Interfaces:
DescribableComponent, CommandGateway

public class DefaultCommandGateway extends Object implements CommandGateway
Default implementation of the CommandGateway interface.
Since:
2.0.0
Author:
Allard Buijze
  • Constructor Details

  • Method Details

    • send

      @Nonnull public CommandResult send(@Nonnull Object command, @Nonnull Metadata metadata, @Nullable ProcessingContext context)
      Description copied from interface: CommandGateway
      Sends the given command with the given metadata in the provided context (if available) 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 CommandGateway
      Parameters:
      command - The command payload or CommandMessage to send.
      metadata - Meta-data that must be registered with the command.
      context - The processing context, if any, to dispatch the given command in.
      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.