public class AxonServerCommandBus extends Object implements CommandBus, Distributed<CommandBus>
CommandBus
implementation that connects to Axon Server to submit and receive commands and command
responses. Delegates incoming commands to the provided localSegment
.Modifier and Type | Class and Description |
---|---|
static class |
AxonServerCommandBus.Builder
Builder class to instantiate an
AxonServerCommandBus . |
Constructor and Description |
---|
AxonServerCommandBus(AxonServerCommandBus.Builder builder)
Instantiate a
AxonServerCommandBus based on the fields contained in the AxonServerCommandBus.Builder . |
AxonServerCommandBus(AxonServerConnectionManager axonServerConnectionManager,
AxonServerConfiguration configuration,
CommandBus localSegment,
Serializer serializer,
RoutingStrategy routingStrategy)
Deprecated.
in favor of using the
AxonServerCommandBus.Builder (with the convenience builder() method) to instantiate
an Axon Server Command Bus |
AxonServerCommandBus(AxonServerConnectionManager axonServerConnectionManager,
AxonServerConfiguration configuration,
CommandBus localSegment,
Serializer serializer,
RoutingStrategy routingStrategy,
CommandPriorityCalculator priorityCalculator)
Deprecated.
in favor of using the
AxonServerCommandBus.Builder (with the convenience builder() method) to instantiate
an Axon Server Command Bus |
AxonServerCommandBus(AxonServerConnectionManager axonServerConnectionManager,
AxonServerConfiguration configuration,
CommandBus localSegment,
Serializer serializer,
RoutingStrategy routingStrategy,
CommandPriorityCalculator priorityCalculator,
TargetContextResolver<? super CommandMessage<?>> targetContextResolver)
Deprecated.
in favor of using the
AxonServerCommandBus.Builder (with the convenience builder() method) to instantiate
an Axon Server Command Bus |
Modifier and Type | Method and Description |
---|---|
static AxonServerCommandBus.Builder |
builder()
Instantiate a Builder to be able to create an
AxonServerCommandBus . |
void |
disconnect()
Disconnect the command bus for receiving commands from Axon Server, by unsubscribing all registered command
handlers.
|
<C> void |
dispatch(CommandMessage<C> command)
Dispatch the given
command to the CommandHandler subscribed to the given command 's name. |
<C,R> void |
dispatch(CommandMessage<C> commandMessage,
CommandCallback<? super C,? super R> commandCallback)
Dispatch the given
command to the CommandHandler subscribed to the given command 's name. |
CommandBus |
localSegment()
Return the message bus of type
MessageBus which is regarded as the local segment for this implementation. |
Registration |
registerDispatchInterceptor(MessageDispatchInterceptor<? super CommandMessage<?>> dispatchInterceptor)
Register the given DispatchInterceptor.
|
Registration |
registerHandlerInterceptor(MessageHandlerInterceptor<? super CommandMessage<?>> handlerInterceptor)
Register the given
handlerInterceptor . |
CompletableFuture<Void> |
shutdownDispatching()
Shutdown the command bus asynchronously for dispatching commands to Axon Server.
|
void |
start()
Start the Axon Server
CommandBus implementation. |
Registration |
subscribe(String commandName,
MessageHandler<? super CommandMessage<?>> messageHandler)
Subscribe the given
handler to commands with the given commandName . |
@Deprecated public AxonServerCommandBus(AxonServerConnectionManager axonServerConnectionManager, AxonServerConfiguration configuration, CommandBus localSegment, Serializer serializer, RoutingStrategy routingStrategy)
AxonServerCommandBus.Builder
(with the convenience builder()
method) to instantiate
an Axon Server Command BusCommandBus
client. Will connect to an Axon Server instance to submit and
receive commands and command responses. The CommandPriorityCalculator
is defaulted to the
CommandPriorityCalculator.defaultCommandPriorityCalculator()
and the TargetContextResolver
defaults to a lambda returning the output from AxonServerConfiguration.getContext()
.axonServerConnectionManager
- a AxonServerConnectionManager
which creates the connection to an Axon
Server platformconfiguration
- the AxonServerConfiguration
containing specifics like the client and
component names used to identify the application in Axon Server among otherslocalSegment
- a CommandBus
handling the incoming commands for the local applicationserializer
- a Serializer
used for de/serialization command requests and responsesroutingStrategy
- a RoutingStrategy
defining where a given CommandMessage
should
be routed to@Deprecated public AxonServerCommandBus(AxonServerConnectionManager axonServerConnectionManager, AxonServerConfiguration configuration, CommandBus localSegment, Serializer serializer, RoutingStrategy routingStrategy, CommandPriorityCalculator priorityCalculator)
AxonServerCommandBus.Builder
(with the convenience builder()
method) to instantiate
an Axon Server Command BusCommandPriorityCalculator
to define the priority of command message among
one another. The TargetContextResolver
defaults to a lambda returning the
output from AxonServerConfiguration.getContext()
.axonServerConnectionManager
- a AxonServerConnectionManager
which creates the connection to an Axon
Server platformconfiguration
- the AxonServerConfiguration
containing client and component names used
to identify the application in Axon ServerlocalSegment
- a CommandBus
handling the incoming commands for the local applicationserializer
- a Serializer
used for de/serialization command requests and responsesroutingStrategy
- a RoutingStrategy
defining where a given CommandMessage
should
be routed topriorityCalculator
- a CommandPriorityCalculator
calculating the request priority based on
the content, and adds this priority to the request@Deprecated public AxonServerCommandBus(AxonServerConnectionManager axonServerConnectionManager, AxonServerConfiguration configuration, CommandBus localSegment, Serializer serializer, RoutingStrategy routingStrategy, CommandPriorityCalculator priorityCalculator, TargetContextResolver<? super CommandMessage<?>> targetContextResolver)
AxonServerCommandBus.Builder
(with the convenience builder()
method) to instantiate
an Axon Server Command BusaxonServerConnectionManager
- a AxonServerConnectionManager
which creates the connection to an Axon
Server platformconfiguration
- the AxonServerConfiguration
containing client and component names used
to identify the application in Axon ServerlocalSegment
- a CommandBus
handling the incoming commands for the local applicationserializer
- a Serializer
used for de/serialization command requests and responsesroutingStrategy
- a RoutingStrategy
defining where a given CommandMessage
should
be routed topriorityCalculator
- a CommandPriorityCalculator
calculating the request priority based on
the content, and adds this priority to the requesttargetContextResolver
- resolves the context a given command should be dispatched inpublic AxonServerCommandBus(AxonServerCommandBus.Builder builder)
AxonServerCommandBus
based on the fields contained in the AxonServerCommandBus.Builder
.builder
- the AxonServerCommandBus.Builder
used to instantiate a AxonServerCommandBus
instancepublic static AxonServerCommandBus.Builder builder()
AxonServerCommandBus
.
The CommandPriorityCalculator
is defaulted to
CommandPriorityCalculator.defaultCommandPriorityCalculator()
and the TargetContextResolver
defaults to a lambda returning the AxonServerConfiguration.getContext()
as the context. 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.
AxonServerCommandBus
@StartHandler(phase=536870911) public void start()
CommandBus
implementation.public <C> void dispatch(CommandMessage<C> command)
CommandBus
command
to the CommandHandler subscribed to the given command
's name. No
feedback is given about the status of the dispatching process. Implementations may return immediately after
asserting a valid handler is registered for the given command.dispatch
in interface CommandBus
C
- The payload type of the command to dispatchcommand
- The Command to dispatchGenericCommandMessage.asCommandMessage(Object)
public <C,R> void dispatch(CommandMessage<C> commandMessage, CommandCallback<? super C,? super R> commandCallback)
CommandBus
command
to the CommandHandler subscribed to the given command
's name. When the
command is processed, one of the callback's methods is called, depending on the result of the processing.
When the method returns, the only guarantee provided by the CommandBus implementation is that the command has
been successfully received. Implementations are highly recommended to perform basic validation of the command
before returning from this method call.
Implementations must start a UnitOfWork when before dispatching the command, and either commit or rollback after
a successful or failed execution, respectively.dispatch
in interface CommandBus
C
- The payload type of the command to dispatchR
- The type of the expected resultcommandMessage
- The Command to dispatchcommandCallback
- The callback to invoke when command processing is completeGenericCommandMessage.asCommandMessage(Object)
public Registration subscribe(String commandName, MessageHandler<? super CommandMessage<?>> messageHandler)
CommandBus
handler
to commands with the given commandName
.
If a subscription already exists for the given name, the behavior is undefined. Implementations may throw an
Exception to refuse duplicate subscription or alternatively decide whether the existing or new handler
gets the subscription.subscribe
in interface CommandBus
commandName
- The name of the command to subscribe the handler tomessageHandler
- The handler instance that handles the given type of commandhandler
. When unsubscribed it will no longer receive commands.public CommandBus localSegment()
Distributed
MessageBus
which is regarded as the local segment for this implementation.
Would return the message bus used to dispatch and handle messages in a local environment to bridge the gap in a
distributed set up.localSegment
in interface Distributed<CommandBus>
MessageBus
which is the local segment for this distributed message bus implementationpublic Registration registerHandlerInterceptor(MessageHandlerInterceptor<? super CommandMessage<?>> handlerInterceptor)
MessageHandlerInterceptorSupport
handlerInterceptor
. After registration, the interceptor will be invoked for each
handled Message on the messaging component that it was registered to, prior to invoking the message's handler.registerHandlerInterceptor
in interface MessageHandlerInterceptorSupport<CommandMessage<?>>
handlerInterceptor
- The interceptor to registerpublic Registration registerDispatchInterceptor(MessageDispatchInterceptor<? super CommandMessage<?>> dispatchInterceptor)
MessageDispatchInterceptorSupport
registerDispatchInterceptor
in interface MessageDispatchInterceptorSupport<CommandMessage<?>>
dispatchInterceptor
- The interceptor to register@ShutdownHandler(phase=536870911) public void disconnect()
Phase.INBOUND_COMMAND_CONNECTOR
phase.@ShutdownHandler(phase=0) public CompletableFuture<Void> shutdownDispatching()
Phase.OUTBOUND_COMMAND_CONNECTORS
phase.Copyright © 2010–2020. All rights reserved.