public class AxonServerCommandBus extends Object implements CommandBus
CommandBus
implementation that connects to Axon Server to submit and receive commands and command
responses. Delegates incoming commands to the provided localSegment
.Constructor and Description |
---|
AxonServerCommandBus(AxonServerConnectionManager axonServerConnectionManager,
AxonServerConfiguration configuration,
CommandBus localSegment,
Serializer serializer,
RoutingStrategy routingStrategy)
Instantiate an Axon Server
CommandBus client. |
AxonServerCommandBus(AxonServerConnectionManager axonServerConnectionManager,
AxonServerConfiguration configuration,
CommandBus localSegment,
Serializer serializer,
RoutingStrategy routingStrategy,
CommandPriorityCalculator priorityCalculator)
Instantiate an Axon Server Command Bus client.
|
Modifier and Type | Method and Description |
---|---|
void |
disconnect()
Disconnect the command bus from the Axon Server.
|
<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. |
Registration |
registerDispatchInterceptor(MessageDispatchInterceptor<? super CommandMessage<?>> dispatchInterceptor)
Register the given DispatchInterceptor.
|
Registration |
registerHandlerInterceptor(MessageHandlerInterceptor<? super CommandMessage<?>> handlerInterceptor)
Register the given
handlerInterceptor . |
Registration |
subscribe(String commandName,
MessageHandler<? super CommandMessage<?>> messageHandler)
Subscribe the given
handler to commands with the given commandName . |
public AxonServerCommandBus(AxonServerConnectionManager axonServerConnectionManager, AxonServerConfiguration configuration, CommandBus localSegment, Serializer serializer, RoutingStrategy routingStrategy)
CommandBus
client. Will connect to an Axon Server instance to submit and
receive commands and command responses.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 topublic AxonServerCommandBus(AxonServerConnectionManager axonServerConnectionManager, AxonServerConfiguration configuration, CommandBus localSegment, Serializer serializer, RoutingStrategy routingStrategy, CommandPriorityCalculator priorityCalculator)
CommandPriorityCalculator
to define the priority of command message among
one another.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 requestpublic <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 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 void disconnect()
public Registration registerDispatchInterceptor(MessageDispatchInterceptor<? super CommandMessage<?>> dispatchInterceptor)
MessageDispatchInterceptorSupport
registerDispatchInterceptor
in interface MessageDispatchInterceptorSupport<CommandMessage<?>>
dispatchInterceptor
- The interceptor to registerCopyright © 2010–2019. All rights reserved.