Class AxonServerCommandBus.Builder

java.lang.Object
org.axonframework.axonserver.connector.command.AxonServerCommandBus.Builder
Enclosing class:
AxonServerCommandBus

public static class AxonServerCommandBus.Builder extends Object
Builder class to instantiate an AxonServerCommandBus.

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

  • Constructor Details

    • Builder

      public Builder()
  • Method Details

    • axonServerConnectionManager

      public AxonServerCommandBus.Builder axonServerConnectionManager(AxonServerConnectionManager axonServerConnectionManager)
      Sets the AxonServerConnectionManager used to create connections between this application and an Axon Server instance.
      Parameters:
      axonServerConnectionManager - an AxonServerConnectionManager used to create connections between this application and an Axon Server instance
      Returns:
      the current Builder instance, for fluent interfacing
    • configuration

      public AxonServerCommandBus.Builder configuration(AxonServerConfiguration configuration)
      Sets the AxonServerConfiguration used to configure several components within the Axon Server Command Bus, like setting the client id or the number of command handling threads used.
      Parameters:
      configuration - an AxonServerConfiguration used to configure several components within the Axon Server Command Bus
      Returns:
      the current Builder instance, for fluent interfacing
    • localSegment

      public AxonServerCommandBus.Builder localSegment(org.axonframework.commandhandling.CommandBus localSegment)
      Sets the local CommandBus used to dispatch incoming commands to the local environment.
      Parameters:
      localSegment - a CommandBus used to dispatch incoming commands to the local environment
      Returns:
      the current Builder instance, for fluent interfacing
    • serializer

      public AxonServerCommandBus.Builder serializer(org.axonframework.serialization.Serializer serializer)
      Sets the Serializer used to de-/serialize incoming and outgoing commands and command results.
      Parameters:
      serializer - a Serializer used to de-/serialize incoming and outgoing commands and command results
      Returns:
      the current Builder instance, for fluent interfacing
    • routingStrategy

      public AxonServerCommandBus.Builder routingStrategy(org.axonframework.commandhandling.distributed.RoutingStrategy routingStrategy)
      Sets the RoutingStrategy used to correctly configure connections between Axon clients and Axon Server.
      Parameters:
      routingStrategy - a RoutingStrategy
      Returns:
      the current Builder instance, for fluent interfacing
    • defaultCommandCallback

      public AxonServerCommandBus.Builder defaultCommandCallback(org.axonframework.commandhandling.CommandCallback<Object,Object> defaultCommandCallback)
      Sets the callback to use when commands are dispatched in a "fire and forget" method, such as AxonServerCommandBus.dispatch(CommandMessage). Defaults to a NoOpCallback. Passing null will result in a NoOpCallback being used.
      Parameters:
      defaultCommandCallback - the callback to invoke when no explicit callback is provided for a command
      Returns:
      the current Builder instance, for fluent interfacing
    • priorityCalculator

      public AxonServerCommandBus.Builder priorityCalculator(CommandPriorityCalculator priorityCalculator)
      Sets the CommandPriorityCalculator used to deduce the priority of an incoming command among other commands, to give precedence over high(er) valued queries for example. Defaults to a CommandPriorityCalculator.defaultCommandPriorityCalculator().
      Parameters:
      priorityCalculator - a CommandPriorityCalculator used to deduce the priority of an incoming command among other commands
      Returns:
      the current Builder instance, for fluent interfacing
    • targetContextResolver

      public AxonServerCommandBus.Builder targetContextResolver(TargetContextResolver<? super org.axonframework.commandhandling.CommandMessage<?>> targetContextResolver)
      Sets the TargetContextResolver used to resolve the target (bounded) context of an ingested CommandMessage. Defaults to returning the AxonServerConfiguration.getContext() on any type of command message being ingested.
      Parameters:
      targetContextResolver - a TargetContextResolver used to resolve the target (bounded) context of an ingested CommandMessage
      Returns:
      the current Builder instance, for fluent interfacing
    • executorServiceBuilder

      public AxonServerCommandBus.Builder executorServiceBuilder(ExecutorServiceBuilder executorServiceBuilder)
      Sets the ExecutorServiceBuilder which builds an ExecutorService based on a given AxonServerConfiguration and BlockingQueue of Runnable. This ExecutorService is used to process incoming commands with. Defaults to a ThreadPoolExecutor, using the AxonServerConfiguration.getCommandThreads() for the pool size, a keep-alive-time of 100ms, the given BlockingQueue as the work queue and an AxonThreadFactory.

      Note that it is highly recommended to use the given BlockingQueue if you are to provide you own executorServiceBuilder, as it ensure the command's priority is taken into consideration. Defaults to ExecutorServiceBuilder.defaultCommandExecutorServiceBuilder().

      Parameters:
      executorServiceBuilder - an ExecutorServiceBuilder used to build an ExecutorService based on the AxonServerConfiguration and a BlockingQueue
      Returns:
      the current Builder instance, for fluent interfacing
    • loadFactorProvider

      public AxonServerCommandBus.Builder loadFactorProvider(CommandLoadFactorProvider loadFactorProvider)
      Sets the CommandLoadFactorProvider which provides the load factor values for all commands this client can handle. The load factor values are sent to AxonServer during command subscription. AxonServer uses these values to balance the dispatching of commands among the client instances. The default implementation of loadFactorProvider returns always CommandLoadFactorProvider.DEFAULT_VALUE
      Parameters:
      loadFactorProvider - a CommandLoadFactorProvider used to get the load factor value for each specific command that this client can handle
      Returns:
      the current Builder instance, for fluent interfacing
    • defaultContext

      public AxonServerCommandBus.Builder defaultContext(String defaultContext)
      Sets the default context for this command bus to connect to.
      Parameters:
      defaultContext - for this bus to connect to.
      Returns:
      the current Builder instance, for fluent interfacing
    • spanFactory

      @Deprecated public AxonServerCommandBus.Builder spanFactory(@Nonnull org.axonframework.tracing.SpanFactory spanFactory)
      Deprecated.
      Use spanFactory(CommandBusSpanFactory) instead as it provides more configurability.
      Sets the SpanFactory implementation to use for providing tracing capabilities. Defaults to a NoOpSpanFactory by default, which provides no tracing capabilities.
      Parameters:
      spanFactory - The SpanFactory implementation
      Returns:
      The current Builder instance, for fluent interfacing.
    • spanFactory

      public AxonServerCommandBus.Builder spanFactory(@Nonnull org.axonframework.commandhandling.CommandBusSpanFactory spanFactory)
      Sets the CommandBusSpanFactory implementation to use for providing tracing capabilities. Defaults to a DefaultCommandBusSpanFactory backed by a NoOpSpanFactory by default, which provides no tracing capabilities.
      Parameters:
      spanFactory - The CommandBusSpanFactory implementation
      Returns:
      The current Builder instance, for fluent interfacing.
    • commandInProgressAwait

      public AxonServerCommandBus.Builder commandInProgressAwait(@Nonnull Duration commandInProgressAwait)
      Sets the duration to wait for in-progress command handlers to complete during shutdown. When disconnect() is called, the command bus will wait up to this duration for active command handlers to finish processing before proceeding with the shutdown. If handlers do not complete within this time, they will be cancelled. Defaults to 5 seconds.
      Parameters:
      commandInProgressAwait - the maximum duration to wait for command handlers to complete
      Returns:
      the current Builder instance, for fluent interfacing
    • build

      public AxonServerCommandBus build()
      Initializes a AxonServerCommandBus as specified through this Builder.
      Returns:
      a AxonServerCommandBus as specified through this Builder
    • buildSerializer

      protected CommandSerializer buildSerializer()
      Build a CommandSerializer using the configured serializer and configuration.
      Returns:
      a CommandSerializer based on the configured serializer and configuration
    • validate

      protected void validate() throws org.axonframework.common.AxonConfigurationException
      Validates whether the fields contained in this Builder are set accordingly.
      Throws:
      org.axonframework.common.AxonConfigurationException - if one field is asserted to be incorrect according to the Builder's specifications