Class AxonServerCommandBusConnector

java.lang.Object
org.axonframework.axonserver.connector.command.AxonServerCommandBusConnector
All Implemented Interfaces:
DescribableComponent, CommandBusConnector

public class AxonServerCommandBusConnector extends Object implements CommandBusConnector
An implementation of the CommandBusConnector that connects to an Axon Server instance to send and receive commands. It uses the Axon Server gRPC API to communicate with the server.
Since:
5.0.0
Author:
Allard Buijze, Mitchell Herrijgers
  • Constructor Details

    • AxonServerCommandBusConnector

      public AxonServerCommandBusConnector(@Nonnull io.axoniq.axonserver.connector.AxonServerConnection connection, @Nonnull AxonServerConfiguration configuration)
      Creates a new AxonServerConnector that communicate with Axon Server using the provided connection.
      Parameters:
      connection - The AxonServerConnection to communicate to Axon Server with.
      configuration - The Axon Server configuration, used to retrieve (e.g.) the AxonServerConfiguration.getClientId() to be set when dispatching commands.
  • Method Details

    • start

      public void start()
      Starts the Axon Server CommandBusConnector implementation.
    • dispatch

      @Nonnull public CompletableFuture<CommandResultMessage> dispatch(@Nonnull CommandMessage command, @Nullable ProcessingContext processingContext)
      Description copied from interface: CommandBusConnector
      Dispatches the given command to the appropriate command bus, which may be local or remote.
      Specified by:
      dispatch in interface CommandBusConnector
      Parameters:
      command - The command message to dispatch.
      processingContext - The processing context for the command.
      Returns:
      A CompletableFuture that will complete with the result of the command handling.
    • subscribe

      public CompletableFuture<Void> subscribe(@Nonnull QualifiedName commandName, int loadFactor)
      Description copied from interface: CommandBusConnector
      Subscribes to a command with the given commandName and a loadFactor.
      Specified by:
      subscribe in interface CommandBusConnector
      Parameters:
      commandName - The QualifiedName of the command to subscribe to.
      loadFactor - The load factor for the command, which can be used to control the distribution of command handling across multiple instances. The load factor should be a positive integer.
      Returns:
      A CompletableFuture that completes successfully when this connector subscribed to the given commandName with the given loadFactor.
    • unsubscribe

      public boolean unsubscribe(@Nonnull QualifiedName commandName)
      Description copied from interface: CommandBusConnector
      Unsubscribes from a command with the given commandName.
      Specified by:
      unsubscribe in interface CommandBusConnector
      Parameters:
      commandName - The QualifiedName of the command to unsubscribe from.
      Returns:
      true if the unsubscription was successful, false otherwise.
    • onIncomingCommand

      public void onIncomingCommand(@Nonnull CommandBusConnector.Handler handler)
      Description copied from interface: CommandBusConnector
      Registers a handler that will be called when an incoming command is received. The handler should process the command and call the provided ResultCallback to indicate success or failure.
      Specified by:
      onIncomingCommand in interface CommandBusConnector
      Parameters:
      handler - A BiConsumer that takes a CommandMessage and a CommandBusConnector.ResultCallback.
    • disconnect

      public CompletableFuture<Void> disconnect()
      Disconnect the command bus for receiving commands from Axon Server, by unsubscribing all registered command handlers and waiting for in-flight commands to complete.

      This shutdown operation is performed in the Phase.INBOUND_COMMAND_CONNECTOR phase.

      Returns:
      A completable future that completed once the AxonServerConnection.commandChannel() has prepared disconnected and handled all in-flight incoming messages.
    • shutdownDispatching

      public CompletableFuture<Void> shutdownDispatching()
      Shutdown the command bus asynchronously for dispatching commands to Axon Server. This process will wait for dispatched commands which have not received a response yet. This shutdown operation is performed in the Phase.OUTBOUND_COMMAND_CONNECTORS phase.
      Returns:
      A completable future which is resolved once all command dispatching activities are completed.
    • 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.