Interface CommandGateway
- All Superinterfaces:
DescribableComponent
- All Known Implementing Classes:
ConvertingCommandGateway,DefaultCommandGateway
This interface provides a friendlier API toward the CommandBus. The
CommandGateway allows for components dispatching commands to wait for the result.
- Since:
- 2.0.0
- Author:
- Allard Buijze
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptiondefault CommandResultSends the givencommandin the providedcontext(if available) and 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.default <R> CompletableFuture<R> send(Object command, Class<R> resultType, ProcessingContext context) Sends the givencommandand returns aCompletableFutureimmediately, without waiting for the command to execute.default CommandResultSends the givencommandwith the givenmetadatain the providedcontext(if available) and returns aCommandResultimmediately, without waiting for the command to execute.send(Object command, Metadata metadata, ProcessingContext context) Sends the givencommandwith the givenmetadatain the providedcontext(if available) and returns aCommandResultimmediately, without waiting for the command to execute.default CommandResultsend(Object command, ProcessingContext context) Sends the givencommandin the providedcontext(if available) and returns aCommandResultimmediately, without waiting for the command to execute.default ObjectsendAndWait(Object command) Send the givencommandand waits for completion.default <R> RsendAndWait(Object command, Class<R> resultType) Send the givencommandand waits for the result converted to theresultType.default <R> RsendAndWait(Object command, Class<R> resultType, ProcessingContext context) Send the givencommandand waits for the result converted to theresultType.default ObjectsendAndWait(Object command, ProcessingContext context) Send the givencommandand waits for completion.Methods inherited from interface org.axonframework.common.infra.DescribableComponent
describeTo
-
Method Details
-
send
@Nonnull CommandResult send(@Nonnull Object command, @Nonnull Metadata metadata, @Nullable ProcessingContext context) Sends the givencommandwith the givenmetadatain the providedcontext(if available) and 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- Meta-data that must be registered with thecommand.context- The processing context, if any, to dispatch the givencommandin.- 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 givencommandin the providedcontext(if available) and 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. - See Also:
-
send
Sends the givencommandin the providedcontext(if available) and 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.context- The processing context, if any, to dispatch the givencommandin.- Returns:
- A command result success and failure hooks can be registered. The
CommandResult.getResultMessage()serves as a shorthand to retrieve the response. - See Also:
-
send
Sends the givencommandwith the givenmetadatain the providedcontext(if available) and 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- Meta-data 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. - See Also:
-
send
@Nonnull default <R> CompletableFuture<R> send(@Nonnull Object command, @Nonnull Class<R> resultType) 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.resultType- The class representing the type of the expected command result.- Returns:
- A
CompletableFuturethat will be resolved successfully or exceptionally based on the eventual command execution result. - See Also:
-
send
@Nonnull default <R> CompletableFuture<R> send(@Nonnull Object command, @Nonnull Class<R> resultType, @Nullable ProcessingContext context) 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.resultType- The class representing the type of the expected command result.context- The processing context, if any, to dispatch the givencommandin.- Returns:
- A
CompletableFuturethat will be resolved successfully or exceptionally based on the eventual command execution result. - See Also:
-
sendAndWait
Send the givencommandand waits for completion.If the command was successful, its result (if any) is discarded. If it was unsuccessful an exception is thrown. Any checked exceptions that may occur as the result of running the command will be wrapped in a
CommandExecutionException.If the result is needed, use
sendAndWait(Object, Class)instead, as it allows for type conversion of the result payload.- Parameters:
command- The command payload orCommandMessageto send.- Returns:
- The payload of the result message, or
nullwhen none is present. - Throws:
CommandExecutionException- When a checked exception occurs while handling the command.- See Also:
-
sendAndWait
Send the givencommandand waits for completion.If the command was successful, its result (if any) is discarded. If it was unsuccessful an exception is thrown. Any checked exceptions that may occur as the result of running the command will be wrapped in a
CommandExecutionException.If the result is needed, use
sendAndWait(Object, Class)instead, as it allows for type conversion of the result payload.- Parameters:
command- The command payload orCommandMessageto send.context- The processing context, if any, to dispatch the givencommandin.- Returns:
- The payload of the result message, or
nullwhen none is present. - Throws:
CommandExecutionException- When a checked exception occurs while handling the command.- See Also:
-
sendAndWait
Send the givencommandand waits for the result converted to theresultType.If the command was successful, its result will be converted to the specified
returnTypeand returned. If it was unsuccessful or conversion failed, an exception is thrown. Any checked exceptions that may occur as the result of running the command will be wrapped in aCommandExecutionException.- Type Parameters:
R- The generic type of the expected response.- Parameters:
command- The command payload orCommandMessageto send.resultType- The class representing the type of the expected command result.- Returns:
- The payload of the result message of type
R, ornullwhen none is present. - Throws:
CommandExecutionException- When a checked exception occurs while handling the command.- See Also:
-
sendAndWait
@Nullable default <R> R sendAndWait(@Nonnull Object command, @Nonnull Class<R> resultType, @Nullable ProcessingContext context) Send the givencommandand waits for the result converted to theresultType.If the command was successful, its result will be converted to the specified
returnTypeand returned. If it was unsuccessful or conversion failed, an exception is thrown. Any checked exceptions that may occur as the result of running the command will be wrapped in aCommandExecutionException.- Type Parameters:
R- The generic type of the expected response.- Parameters:
command- The command payload orCommandMessageto send.resultType- The class representing the type of the expected command result.context- The processing context, if any, to dispatch the givencommandin.- Returns:
- The payload of the result message of type
R, ornullwhen none is present. - Throws:
CommandExecutionException- When a checked exception occurs while handling the command.
-