Interface CommandDispatcher
- All Superinterfaces:
DescribableComponent
- All Known Implementing Classes:
ContextAwareCommandDispatcher
CommandGateway in a predefined
context. This makes the CommandDispatcher the preferred way to send commands from within another message handling method.
The commands will be dispatched in the context this dispatcher was created for. You can construct one through the
forContext(ProcessingContext).
When using annotation-based @MessageHandler-methods and
you have declared an argument of type CommandDispatcher, the dispatcher will automatically be injected by the
CommandDispatcherParameterResolverFactory.
As this component is ProcessingContext-scoped, it is not retrievable from the Configuration.
- Since:
- 5.0.0
- Author:
- Steven van Beelen
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic CommandDispatcherforContext(ProcessingContext context) Creates a dispatcher for the givenProcessingContext.Sends the givencommandand returns aCommandResultimmediately, without waiting for the command to execute.default <R> CompletableFuture<R> Sends the givencommandand returns aCompletableFutureimmediately, without waiting for the command to execute.Sends the givencommandwith the givenmetadataand returns aCommandResultimmediately, without waiting for the command to execute.Methods inherited from interface org.axonframework.common.infra.DescribableComponent
describeTo
-
Field Details
-
RESOURCE_KEY
-
-
Method Details
-
forContext
Creates a dispatcher for the givenProcessingContext.You can use this dispatcher only for the context it was created for. There is no harm in using this method more than once with the same
context, as the same dispatcher will be returned.- Parameters:
context- TheProcessingContextto create the dispatcher for.- Returns:
- The command dispatcher specific for the given
context.
-
send
Sends the givencommandand returns aCompletableFutureimmediately, without waiting for the command to execute.The caller will therefore not receive any immediate feedback on the
command'sexecution. Instead, hooks can be added to the returnedCompletableFutureto react on success or failure of command execution.Note that this operation expects the
The givenCommandBusto use new threads for command execution.commandis wrapped as the payload of theCommandMessagethat is eventually posted on theCommandBus, unless thecommandalready implementsMessage. In that case, aCommandMessageis constructed from that message's payload andMetadata.- Type Parameters:
R- The generic type of the expected response.- Parameters:
command- The command payload orCommandMessageto send.expectedType- The expected result type.- Returns:
- A
CompletableFuturethat will be resolved successfully or exceptionally based on the eventual command execution result.
-
send
Sends the givencommandand returns aCommandResultimmediately, without waiting for the command to execute.The caller will therefore not receive any immediate feedback on the
command'sexecution. Instead, hooks can be added to the returnedCommandResultto react on success or failure of command execution. A shorthand to retrieve aCompletableFutureis available through theCommandResult.getResultMessage()operation.Note that this operation expects the
The givenCommandBusto use new threads for command execution.commandis wrapped as the payload of theCommandMessagethat is eventually posted on theCommandBus, unless thecommandalready implementsMessage. In that case, aCommandMessageis constructed from that message's payload andMetadata.- Parameters:
command- The command payload orCommandMessageto send.- Returns:
- A command result success and failure hooks can be registered. The
CommandResult.getResultMessage()serves as a shorthand to retrieve the response.
-
send
Sends the givencommandwith the givenmetadataand returns aCommandResultimmediately, without waiting for the command to execute.The caller will therefore not receive any immediate feedback on the
command'sexecution. Instead, hooks can be added to the returnedCommandResultto react on success or failure of command execution. A shorthand to retrieve aCompletableFutureis available through theCommandResult.getResultMessage()operation.Note that this operation expects the
The givenCommandBusto use new threads for command execution.commandandmetadataare wrapped as the payload of theCommandMessagethat is eventually posted on theCommandBus, unless thecommandalready implementsMessage. In that case, aCommandMessageis constructed from that message's payload andMetadata. The providedmetadatais attached afterward in this case.- Parameters:
command- The command payload orCommandMessageto send.metadata- Metadata that must be registered with thecommand.- Returns:
- A command result success and failure hooks can be registered. The
CommandResult.getResultMessage()serves as a shorthand to retrieve the response.
-