Class ConvertingCommandGateway
- All Implemented Interfaces:
DescribableComponent,CommandGateway
CommandGateway implementation that wraps the CommandResult of the delegate into a result that can
convert the payload of the result using a provided MessageConverter.- Since:
- 5.0.0
- Author:
- Allard Buijze, Mitchell Herrijgers
-
Constructor Summary
ConstructorsConstructorDescriptionConvertingCommandGateway(CommandGateway delegate, MessageConverter converter) Constructs aConvertingCommandGatewaywith the givendelegateandconverter. -
Method Summary
Modifier and TypeMethodDescriptionvoiddescribeTo(ComponentDescriptor descriptor) Describe the properties ofthis DescribableComponentwith the givendescriptor.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.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.axonframework.messaging.commandhandling.gateway.CommandGateway
send, send, send, send, send, sendAndWait, sendAndWait, sendAndWait, sendAndWait
-
Constructor Details
-
ConvertingCommandGateway
public ConvertingCommandGateway(@Nonnull CommandGateway delegate, @Nonnull MessageConverter converter) Constructs aConvertingCommandGatewaywith the givendelegateandconverter.- Parameters:
delegate- The delegate command gateway to wrap within this command gateway.converter- The converter to use for converting the result of command handling.
-
-
Method Details
-
send
@Nonnull public CommandResult send(@Nonnull Object command, @Nonnull Metadata metadata, @Nullable ProcessingContext context) Description copied from interface:CommandGatewaySends 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.- Specified by:
sendin interfaceCommandGateway- 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.
-
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.
-