Class AxonServerCommandBusConnector
- All Implemented Interfaces:
DescribableComponent,CommandBusConnector
CommandBusConnector that connects to an Axon Server instance to send and receive
commands. It uses the Axon Server gRPC API to communicate with the server.- Since:
- 5.0.0
- Author:
- Allard Buijze, Mitchell Herrijgers
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.axonframework.messaging.commandhandling.distributed.CommandBusConnector
CommandBusConnector.Handler, CommandBusConnector.ResultCallback -
Constructor Summary
ConstructorsConstructorDescriptionAxonServerCommandBusConnector(io.axoniq.axonserver.connector.AxonServerConnection connection, AxonServerConfiguration configuration) Creates a newAxonServerConnectorthat communicate with Axon Server using the providedconnection. -
Method Summary
Modifier and TypeMethodDescriptionvoiddescribeTo(ComponentDescriptor descriptor) Describe the properties ofthis DescribableComponentwith the givendescriptor.Disconnect the command bus for receiving commands from Axon Server, by unsubscribing all registered command handlers and waiting for in-flight commands to complete.dispatch(CommandMessage command, ProcessingContext processingContext) Dispatches the givencommandto the appropriate command bus, which may be local or remote.voidRegisters a handler that will be called when an incoming command is received.Shutdown the command bus asynchronously for dispatching commands to Axon Server.voidstart()Starts the Axon ServerCommandBusConnectorimplementation.subscribe(QualifiedName commandName, int loadFactor) Subscribes to a command with the givencommandNameand aloadFactor.booleanunsubscribe(QualifiedName commandName) Unsubscribes from a command with the givencommandName.
-
Constructor Details
-
AxonServerCommandBusConnector
public AxonServerCommandBusConnector(@Nonnull io.axoniq.axonserver.connector.AxonServerConnection connection, @Nonnull AxonServerConfiguration configuration) Creates a newAxonServerConnectorthat communicate with Axon Server using the providedconnection.- Parameters:
connection- TheAxonServerConnectionto communicate to Axon Server with.configuration- The Axon Server configuration, used to retrieve (e.g.) theAxonServerConfiguration.getClientId()to be set whendispatchingcommands.
-
-
Method Details
-
start
public void start()Starts the Axon ServerCommandBusConnectorimplementation. -
dispatch
@Nonnull public CompletableFuture<CommandResultMessage> dispatch(@Nonnull CommandMessage command, @Nullable ProcessingContext processingContext) Description copied from interface:CommandBusConnectorDispatches the givencommandto the appropriate command bus, which may be local or remote.- Specified by:
dispatchin interfaceCommandBusConnector- Parameters:
command- The command message to dispatch.processingContext- The processing context for the command.- Returns:
- A
CompletableFuturethat will complete with the result of the command handling.
-
subscribe
Description copied from interface:CommandBusConnectorSubscribes to a command with the givencommandNameand aloadFactor.- Specified by:
subscribein interfaceCommandBusConnector- Parameters:
commandName- TheQualifiedNameof the command to subscribe to.loadFactor- The load factor for the command, which can be used to control the distribution of command handling across multiple instances. The load factor should be a positive integer.- Returns:
- A
CompletableFuturethat completes successfully when this connector subscribed to the givencommandNamewith the givenloadFactor.
-
unsubscribe
Description copied from interface:CommandBusConnectorUnsubscribes from a command with the givencommandName.- Specified by:
unsubscribein interfaceCommandBusConnector- Parameters:
commandName- TheQualifiedNameof the command to unsubscribe from.- Returns:
trueif the unsubscription was successful,falseotherwise.
-
onIncomingCommand
Description copied from interface:CommandBusConnectorRegisters a handler that will be called when an incoming command is received. The handler should process the command and call the providedResultCallbackto indicate success or failure.- Specified by:
onIncomingCommandin interfaceCommandBusConnector- Parameters:
handler- ABiConsumerthat takes aCommandMessageand aCommandBusConnector.ResultCallback.
-
disconnect
Disconnect the command bus for receiving commands from Axon Server, by unsubscribing all registered command handlers and waiting for in-flight commands to complete.This shutdown operation is performed in the
Phase.INBOUND_COMMAND_CONNECTORphase.- Returns:
- A completable future that completed once the
AxonServerConnection.commandChannel()has prepared disconnected and handled all in-flight incoming messages.
-
shutdownDispatching
Shutdown the command bus asynchronously for dispatching commands to Axon Server. This process will wait for dispatched commands which have not received a response yet. This shutdown operation is performed in thePhase.OUTBOUND_COMMAND_CONNECTORSphase.- Returns:
- A completable future which is resolved once all command dispatching activities are completed.
-
describeTo
Description copied from interface:DescribableComponentDescribe the properties ofthis DescribableComponentwith the givendescriptor.Components should call the appropriate
describePropertymethods on the descriptor to register their properties. The descriptor is responsible for determining how these properties are formatted and structured in the final output.Best Practices: As a general rule, all relevant fields of a
DescribableComponentimplementation should be described in this method. However, developers have discretion to include only the fields that make sense in the context. Not every field may be meaningful for description purposes, especially internal implementation details. Furthermore, components might want to expose different information based on their current state. The final decision on what properties to include lies with the person implementing thedescribeTomethod, who should focus on providing information that is useful for understanding the component's configuration and state.Example implementation:
public void describeTo(ComponentDescriptor descriptor) { descriptor.describeProperty("name", this.name); descriptor.describeProperty("enabled", this.enabled); descriptor.describeProperty("configuration", this.configuration); // A nested component descriptor.describeProperty("handlers", this.eventHandlers); // A collection }- Specified by:
describeToin interfaceDescribableComponent- Parameters:
descriptor- The component descriptor to describethis DescribableComponentn its properties in.
-