public class AxonServerCommandBus extends Object implements CommandBus, Distributed<CommandBus>, Lifecycle
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. |
Lifecycle.LifecycleHandler, Lifecycle.LifecycleRegistry| Constructor and Description |
|---|
AxonServerCommandBus(AxonServerCommandBus.Builder builder)
Instantiate a
AxonServerCommandBus based on the fields contained in the AxonServerCommandBus.Builder. |
| Modifier and Type | Method and Description |
|---|---|
static AxonServerCommandBus.Builder |
builder()
Instantiate a Builder to be able to create an
AxonServerCommandBus. |
CompletableFuture<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. |
void |
registerLifecycleHandlers(Lifecycle.LifecycleRegistry handle)
Registers the activities to be executed in the various phases of an application's lifecycle.
|
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. |
public 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(), the TargetContextResolver defaults
to a lambda returning the AxonServerConfiguration.getContext() as the context and the SpanFactory
defaults to 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.
AxonServerCommandBuspublic void registerLifecycleHandlers(@Nonnull Lifecycle.LifecycleRegistry handle)
LifecycleregisterLifecycleHandlers in interface Lifecyclehandle - the lifecycle instance to register the handlers withLifecycle.LifecycleRegistry.onShutdown(int, Runnable),
LifecycleRegistry#onShutdown(int, LifecycleHandler),
Lifecycle.LifecycleRegistry.onStart(int, Runnable),
LifecycleRegistry#onStart(int, LifecycleHandler)public void start()
CommandBus implementation.public <C> void dispatch(@Nonnull CommandMessage<C> command)
CommandBuscommand 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 CommandBusC - The payload type of the command to dispatchcommand - The Command to dispatchGenericCommandMessage.asCommandMessage(Object)public <C,R> void dispatch(@Nonnull CommandMessage<C> commandMessage, @Nonnull CommandCallback<? super C,? super R> commandCallback)
CommandBuscommand 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.
There are no guarantees about the successful completion of command dispatching or handling after the method
returns. 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 CommandBusC - 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(@Nonnull String commandName, @Nonnull MessageHandler<? super CommandMessage<?>> messageHandler)
CommandBushandler 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 CommandBuscommandName - 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()
DistributedMessageBus 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(@Nonnull MessageHandlerInterceptor<? super CommandMessage<?>> handlerInterceptor)
MessageHandlerInterceptorSupporthandlerInterceptor. 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(@Nonnull MessageDispatchInterceptor<? super CommandMessage<?>> dispatchInterceptor)
MessageDispatchInterceptorSupportregisterDispatchInterceptor in interface MessageDispatchInterceptorSupport<CommandMessage<?>>dispatchInterceptor - The interceptor to registerpublic CompletableFuture<Void> disconnect()
Phase.INBOUND_COMMAND_CONNECTOR phase.public CompletableFuture<Void> shutdownDispatching()
Phase.OUTBOUND_COMMAND_CONNECTORS phase.Copyright © 2010–2023. All rights reserved.