Class DefaultCommandGateway
- All Implemented Interfaces:
DescribableComponent,CommandGateway
CommandGateway interface.- Since:
- 2.0.0
- Author:
- Allard Buijze
-
Constructor Summary
ConstructorsConstructorDescriptionDefaultCommandGateway(CommandBus commandBus, MessageTypeResolver messageTypeResolver, CommandPriorityCalculator priorityCalculator, RoutingStrategy routingKeyResolver) Initialize theDefaultCommandGatewayto send commands through givencommandBus. -
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
-
DefaultCommandGateway
public DefaultCommandGateway(@Nonnull CommandBus commandBus, @Nonnull MessageTypeResolver messageTypeResolver, @Nonnull CommandPriorityCalculator priorityCalculator, @Nonnull RoutingStrategy routingKeyResolver) Initialize theDefaultCommandGatewayto send commands through givencommandBus.The
namesforCommandMessagesare resolved through the givennameResolver.- Parameters:
commandBus- TheCommandBusto send commands on.messageTypeResolver- TheMessageTypeResolverresolving thenamesforCommandMessagesbeing dispatched on thecommandBus.priorityCalculator- TheCommandPriorityCalculatordetermining the priority of commands.routingKeyResolver- TheRoutingStrategydetermining the routing key for commands.
-
-
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.
-