Class AxonServerCommandBus

java.lang.Object
org.axonframework.axonserver.connector.command.AxonServerCommandBus
All Implemented Interfaces:
org.axonframework.commandhandling.CommandBus, org.axonframework.lifecycle.Lifecycle, org.axonframework.messaging.Distributed<org.axonframework.commandhandling.CommandBus>, org.axonframework.messaging.MessageDispatchInterceptorSupport<org.axonframework.commandhandling.CommandMessage<?>>, org.axonframework.messaging.MessageHandlerInterceptorSupport<org.axonframework.commandhandling.CommandMessage<?>>

public class AxonServerCommandBus extends Object implements org.axonframework.commandhandling.CommandBus, org.axonframework.messaging.Distributed<org.axonframework.commandhandling.CommandBus>, org.axonframework.lifecycle.Lifecycle
Axon CommandBus implementation that connects to Axon Server to submit and receive commands and command responses. Delegates incoming commands to the provided localSegment.
Since:
4.0
Author:
Marc Gathier
  • Constructor Details

  • Method Details

    • builder

      public static AxonServerCommandBus.Builder builder()
      Instantiate a Builder to be able to create an AxonServerCommandBus.

      The CommandPriorityCalculator is defaulted to CommandPriorityCalculator.defaultCommandPriorityCalculator(), the TargetContextResolver defaults to a lambda returning the AxonServerConfiguration.getContext() as the context and the CommandBusSpanFactory defaults to a DefaultCommandBusSpanFactory backed by a NoOpSpanFactory. The ExecutorServiceBuilder defaults to ExecutorServiceBuilder.defaultCommandExecutorServiceBuilder(). The AxonServerConnectionManager, the AxonServerConfiguration, the local CommandBus, Serializer and the RoutingStrategy are a hard requirements and as such should be provided.

      Returns:
      a Builder to be able to create a AxonServerCommandBus
    • registerLifecycleHandlers

      public void registerLifecycleHandlers(@Nonnull org.axonframework.lifecycle.Lifecycle.LifecycleRegistry handle)
      Specified by:
      registerLifecycleHandlers in interface org.axonframework.lifecycle.Lifecycle
    • start

      public void start()
      Start the Axon Server CommandBus implementation.
    • dispatch

      public <C> void dispatch(@Nonnull org.axonframework.commandhandling.CommandMessage<C> command)
      Specified by:
      dispatch in interface org.axonframework.commandhandling.CommandBus
    • dispatch

      public <C, R> void dispatch(@Nonnull org.axonframework.commandhandling.CommandMessage<C> commandMessage, @Nonnull org.axonframework.commandhandling.CommandCallback<? super C,? super R> commandCallback)
      Specified by:
      dispatch in interface org.axonframework.commandhandling.CommandBus
    • subscribe

      public org.axonframework.common.Registration subscribe(@Nonnull String commandName, @Nonnull org.axonframework.messaging.MessageHandler<? super org.axonframework.commandhandling.CommandMessage<?>> messageHandler)
      Specified by:
      subscribe in interface org.axonframework.commandhandling.CommandBus
    • localSegment

      public org.axonframework.commandhandling.CommandBus localSegment()
      Specified by:
      localSegment in interface org.axonframework.messaging.Distributed<org.axonframework.commandhandling.CommandBus>
    • registerHandlerInterceptor

      public org.axonframework.common.Registration registerHandlerInterceptor(@Nonnull org.axonframework.messaging.MessageHandlerInterceptor<? super org.axonframework.commandhandling.CommandMessage<?>> handlerInterceptor)
      Specified by:
      registerHandlerInterceptor in interface org.axonframework.messaging.MessageHandlerInterceptorSupport<org.axonframework.commandhandling.CommandMessage<?>>
    • registerDispatchInterceptor

      public org.axonframework.common.Registration registerDispatchInterceptor(@Nonnull org.axonframework.messaging.MessageDispatchInterceptor<? super org.axonframework.commandhandling.CommandMessage<?>> dispatchInterceptor)
      Specified by:
      registerDispatchInterceptor in interface org.axonframework.messaging.MessageDispatchInterceptorSupport<org.axonframework.commandhandling.CommandMessage<?>>
    • disconnect

      public CompletableFuture<Void> disconnect()
      Disconnect the command bus for receiving commands from Axon Server, by unsubscribing all registered command handlers. This shutdown operation is performed in the Phase.INBOUND_COMMAND_CONNECTOR phase.

      This method will wait for in-progress command handlers to complete, up to the configured commandInProgressAwait duration. If handlers do not complete within this time, they will be cancelled.

    • 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