Class AxonServerCommandBus.Builder
java.lang.Object
org.axonframework.axonserver.connector.command.AxonServerCommandBus.Builder
- Enclosing class:
AxonServerCommandBus
Builder class to instantiate an
AxonServerCommandBus.
The CommandPriorityCalculator is defaulted to
and the invalid @link
{@link CommandPriorityCalculator#defaultCommandPriorityCalculator(),
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaxonServerConnectionManager(AxonServerConnectionManager axonServerConnectionManager) Sets theAxonServerConnectionManagerused to create connections between this application and an Axon Server instance.build()Initializes aAxonServerCommandBusas specified through this Builder.protected CommandSerializercommandInProgressAwait(Duration commandInProgressAwait) Sets the duration to wait for in-progress command handlers to complete during shutdown.configuration(AxonServerConfiguration configuration) Sets theAxonServerConfigurationused to configure several components within the Axon Server Command Bus, like setting the client id or the number of command handling threads used.defaultCommandCallback(CommandCallback<Object, Object> defaultCommandCallback) Sets the callback to use when commands are dispatched in a "fire and forget" method, such asAxonServerCommandBus.dispatch(CommandMessage).defaultContext(String defaultContext) Sets the default context for this command bus to connect to.executorServiceBuilder(ExecutorServiceBuilder executorServiceBuilder) Sets theExecutorServiceBuilderwhich builds anExecutorServicebased on a givenAxonServerConfigurationandBlockingQueueofRunnable.loadFactorProvider(CommandLoadFactorProvider loadFactorProvider) Sets theCommandLoadFactorProviderwhich provides the load factor values for all commands this client can handle.localSegment(CommandBus localSegment) Sets the localCommandBusused to dispatch incoming commands to the local environment.priorityCalculator(CommandPriorityCalculator priorityCalculator) Sets theCommandPriorityCalculatorused to deduce the priority of an incoming command among other commands, to give precedence over high(er) valued queries for example.routingStrategy(RoutingStrategy routingStrategy) Sets theRoutingStrategyused to correctly configure connections between Axon clients and Axon Server.serializer(Serializer serializer) Sets theSerializerused to de-/serialize incoming and outgoing commands and command results.spanFactory(CommandBusSpanFactory spanFactory) Sets theCommandBusSpanFactoryimplementation to use for providing tracing capabilities.spanFactory(SpanFactory spanFactory) Deprecated.targetContextResolver(TargetContextResolver<? super CommandMessage<?>> targetContextResolver) Sets theTargetContextResolverused to resolve the target (bounded) context of an ingestedCommandMessage.protected voidvalidate()Validates whether the fields contained in this Builder are set accordingly.
-
Constructor Details
-
Builder
public Builder()
-
-
Method Details
-
axonServerConnectionManager
public AxonServerCommandBus.Builder axonServerConnectionManager(AxonServerConnectionManager axonServerConnectionManager) Sets theAxonServerConnectionManagerused to create connections between this application and an Axon Server instance.- Parameters:
axonServerConnectionManager- anAxonServerConnectionManagerused to create connections between this application and an Axon Server instance- Returns:
- the current Builder instance, for fluent interfacing
-
configuration
Sets theAxonServerConfigurationused 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- anAxonServerConfigurationused to configure several components within the Axon Server Command Bus- Returns:
- the current Builder instance, for fluent interfacing
-
localSegment
Sets the localCommandBusused to dispatch incoming commands to the local environment.- Parameters:
localSegment- aCommandBusused to dispatch incoming commands to the local environment- Returns:
- the current Builder instance, for fluent interfacing
-
serializer
Sets theSerializerused to de-/serialize incoming and outgoing commands and command results.- Parameters:
serializer- aSerializerused to de-/serialize incoming and outgoing commands and command results- Returns:
- the current Builder instance, for fluent interfacing
-
routingStrategy
Sets theRoutingStrategyused to correctly configure connections between Axon clients and Axon Server.- Parameters:
routingStrategy- aRoutingStrategy- Returns:
- the current Builder instance, for fluent interfacing
-
defaultCommandCallback
public AxonServerCommandBus.Builder defaultCommandCallback(CommandCallback<Object, Object> defaultCommandCallback) Sets the callback to use when commands are dispatched in a "fire and forget" method, such asAxonServerCommandBus.dispatch(CommandMessage). Defaults to aNoOpCallback. Passingnullwill result in aNoOpCallbackbeing 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 theCommandPriorityCalculatorused to deduce the priority of an incoming command among other commands, to give precedence over high(er) valued queries for example. Defaults to aCommandPriorityCalculator.defaultCommandPriorityCalculator().- Parameters:
priorityCalculator- aCommandPriorityCalculatorused 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 CommandMessage<?>> targetContextResolver) Sets theTargetContextResolverused to resolve the target (bounded) context of an ingestedCommandMessage. Defaults to returning theAxonServerConfiguration.getContext()on any type of command message being ingested.- Parameters:
targetContextResolver- aTargetContextResolverused to resolve the target (bounded) context of an ingestedCommandMessage- Returns:
- the current Builder instance, for fluent interfacing
-
executorServiceBuilder
public AxonServerCommandBus.Builder executorServiceBuilder(ExecutorServiceBuilder executorServiceBuilder) Sets theExecutorServiceBuilderwhich builds anExecutorServicebased on a givenAxonServerConfigurationandBlockingQueueofRunnable. This ExecutorService is used to process incoming commands with. Defaults to aThreadPoolExecutor, using theAxonServerConfiguration.getCommandThreads()for the pool size, a keep-alive-time of100ms, the given BlockingQueue as the work queue and anAxonThreadFactory. Note that it is highly recommended to use the given BlockingQueue if you are to provide you ownexecutorServiceBuilder, as it ensure the command's priority is taken into consideration. Defaults toExecutorServiceBuilder.defaultCommandExecutorServiceBuilder().- Parameters:
executorServiceBuilder- anExecutorServiceBuilderused to build anExecutorServicebased on theAxonServerConfigurationand aBlockingQueue- Returns:
- the current Builder instance, for fluent interfacing
-
loadFactorProvider
public AxonServerCommandBus.Builder loadFactorProvider(CommandLoadFactorProvider loadFactorProvider) Sets theCommandLoadFactorProviderwhich 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 alwaysCommandLoadFactorProvider.DEFAULT_VALUE- Parameters:
loadFactorProvider- aCommandLoadFactorProviderused to get the load factor value for each specific command that this client can handle- Returns:
- the current Builder instance, for fluent interfacing
-
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.UsespanFactory(CommandBusSpanFactory)instead as it provides more configurability.Sets theSpanFactoryimplementation to use for providing tracing capabilities. Defaults to aNoOpSpanFactoryby default, which provides no tracing capabilities.- Parameters:
spanFactory- TheSpanFactoryimplementation- Returns:
- The current Builder instance, for fluent interfacing.
-
spanFactory
Sets theCommandBusSpanFactoryimplementation to use for providing tracing capabilities. Defaults to aDefaultCommandBusSpanFactorybacked by aNoOpSpanFactoryby default, which provides no tracing capabilities.- Parameters:
spanFactory- TheCommandBusSpanFactoryimplementation- 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. Whendisconnect()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
Initializes aAxonServerCommandBusas specified through this Builder.- Returns:
- a
AxonServerCommandBusas specified through this Builder
-
buildSerializer
- Returns:
- a
CommandSerializerbased on the configuredserializerandconfiguration
-
validate
Validates whether the fields contained in this Builder are set accordingly.- Throws:
AxonConfigurationException- if one field is asserted to be incorrect according to the Builder's specifications
-
spanFactory(CommandBusSpanFactory)instead as it provides more configurability.