Class LocalShortcutCommandBusConnector
- All Implemented Interfaces:
CommandBusConnector,DescribableComponent
CommandBusConnector that offers a "local shortcut".
This shortcut triggers for commands matching a LocalCommandDispatchPredicate, and for which the local segment
subscribed a handler, the command is handed to the local segment directly instead of being
dispatched through the wrapped connector. Furthermore, the
shortcut only activates when the local segment can actually handle the command, tracked through the
subscribe(QualifiedName, int)/unsubscribe(QualifiedName) calls this connector observes.
Short-cut commands are handled through the same CommandBusConnector.Handler as any other CommandBusConnector. As such,
they are queued onto and executed by the same bounded, priority-ordered worker pool as commands arriving from remote
segments. A burst of locally-preferred commands is therefore subject to the same back-pressure and cannot flood the
local segment beyond what it would already accept from remote traffic.
- Since:
- 5.4.0
- Author:
- Allard Buijze
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface io.axoniq.framework.messaging.commandhandling.distributed.CommandBusConnector
CommandBusConnector.Handler, CommandBusConnector.ResultCallback -
Field Summary
Fields inherited from class io.axoniq.framework.messaging.commandhandling.distributed.DelegatingCommandBusConnector
delegate -
Constructor Summary
ConstructorsConstructorDescriptionLocalShortcutCommandBusConnector(CommandBusConnector delegate, LocalCommandDispatchPredicate shortcutPredicate) Initialize a connector with the givendelegate, using the givenshortcutPredicateto decide whether to shortcut a command yes or no. -
Method Summary
Modifier and TypeMethodDescriptionvoiddescribeTo(ComponentDescriptor descriptor) Describe the properties ofthis DescribableComponentwith the givendescriptor.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.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
-
LocalShortcutCommandBusConnector
public LocalShortcutCommandBusConnector(CommandBusConnector delegate, LocalCommandDispatchPredicate shortcutPredicate) Initialize a connector with the givendelegate, using the givenshortcutPredicateto decide whether to shortcut a command yes or no.- Parameters:
delegate- theCommandBusConnectorto delegate to when not dispatching locallyshortcutPredicate- the predicate deciding whether a command should be dispatched to the local segment directly
-
-
Method Details
-
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- Overrides:
dispatchin classDelegatingCommandBusConnector- 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- Overrides:
subscribein classDelegatingCommandBusConnector- 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- Overrides:
unsubscribein classDelegatingCommandBusConnector- 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- Overrides:
onIncomingCommandin classDelegatingCommandBusConnector- Parameters:
handler- ABiConsumerthat takes aCommandMessageand aCommandBusConnector.ResultCallback.
-
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- Overrides:
describeToin classDelegatingCommandBusConnector- Parameters:
descriptor- The component descriptor to describethis DescribableComponentn its properties in.
-