Class SpringCloudCommandBusConnector
- All Implemented Interfaces:
CommandBusConnector,DescribableComponent
CommandBusConnector distributing commands across the nodes discovered through Spring Cloud Discovery.
With no server to route for it, this connector routes itself. Every dispatch resolves a Member from the
SpringCloudMemberDiscovery's consistent-hash ring, using the command's routing key and name, and then either
hands the command to this application's own handler or sends it to the resolved member over HTTP. That is the shape
of the Axon Framework 5 contract: DistributedCommandBus passes a dispatch straight through, so routing is
the connector's job.
Two consequences of that are worth being explicit about:
- A command routed to this application is delivered through the
CommandBusConnector.Handlerregistered byDistributedCommandBus, never by calling a localCommandBusdirectly. That handler owns the priority-ordered executor and the local segment, so bypassing it would lose command priority and the bus's own interception. subscribe(QualifiedName, int)completes immediately, recording the subscription locally and publishing the updated capabilities. It deliberately does not wait for other members to observe the change:DistributedCommandBusjoins this future on the subscribing thread, and other members learn of the subscription when they next refresh its capabilities regardless.
SpringCloudConfigurationEnhancer, wrapped in a
PayloadConvertingCommandBusConnector that converts payloads to String on the way out. It is not
meant to be constructed directly by application code.- Since:
- 5.4.0
- Author:
- Allard Buijze
-
Nested Class Summary
Nested classes/interfaces inherited from interface io.axoniq.framework.messaging.commandhandling.distributed.CommandBusConnector
CommandBusConnector.Handler, CommandBusConnector.ResultCallback -
Constructor Summary
ConstructorsConstructorDescriptionSpringCloudCommandBusConnector(SpringCloudMemberDiscovery discovery, IncomingCommandInvoker invoker, RemoteCommandDispatcher dispatcher, @Nullable MessageConverter converter) Constructs aSpringCloudCommandBusConnectorrouting with the givendiscovery. -
Method Summary
Modifier and TypeMethodDescriptionvoiddescribeTo(ComponentDescriptor descriptor) Describe the properties ofthis DescribableComponentwith the givendescriptor.Stops advertising the commands this member handles, so that other members stop routing them here.dispatch(CommandMessage command, @Nullable 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.Stops dispatching new commands, and waits for the ones already dispatched to be answered.voidstart()Starts this connector, allowing commands to be dispatched through it.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
-
Method Details
-
start
public void start()Starts this connector, allowing commands to be dispatched through it.Performed in the
Phase.INBOUND_COMMAND_CONNECTORphase. -
dispatch
public CompletableFuture<CommandResultMessage> dispatch(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 dispatchprocessingContext- 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.Subscribing a
commandNamethis connector is already subscribed to replaces the earlier subscription, adopting the givenloadFactor. A singleunsubscribeof thatcommandNameundoes any number of subscriptions to it.- 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.Undoes any number of
subscriptionsto the givencommandName, leaving no command of that name routed to this connector.- 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
Stops advertising the commands this member handles, so that other members stop routing them here.Performed in the
Phase.INBOUND_COMMAND_CONNECTORphase. Incoming commands arrive over HTTP, so it is the web container's own graceful shutdown that stops new requests; this connector's part is to publish empty capabilities, so that members still running route around it on their next discovery round rather than sending commands into a closing container.- Returns:
- a future that completes once this member no longer advertises any command
-
shutdownDispatching
Stops dispatching new commands, and waits for the ones already dispatched to be answered.Performed in the
Phase.OUTBOUND_COMMAND_CONNECTORSphase.- Returns:
- a future that completes once every dispatched command has been answered
-
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.
-