Interface CommandBusConnector
- All Superinterfaces:
MessageHandlerInterceptorSupport<CommandMessage<?>>
Interface describing the component that remotely connects multiple CommandBus instances.
- Since:
- 2.0
- Author:
- Allard Buijze
-
Method Summary
Modifier and TypeMethodDescriptiondefault CompletableFuture<Void> Initiate the shutdown of aCommandBusConnector.default Optional<CommandBus> Return anOptionalcontaining theCommandBuswhich is used by thisCommandBusConnectorto dispatch local and incomingCommandMessages on.<C> voidsend(Member destination, CommandMessage<? extends C> command) Sends the givencommandto the node assigned to handle messages with the givenroutingKey.<C,R> void send(Member destination, CommandMessage<C> command, CommandCallback<? super C, R> callback) Sends the givencommandto the node assigned to handle messages with the givenroutingKey.subscribe(String commandName, MessageHandler<? super CommandMessage<?>> handler) Subscribes a command message handler for commands with givencommandName.Methods inherited from interface org.axonframework.messaging.MessageHandlerInterceptorSupport
registerHandlerInterceptor
-
Method Details
-
send
<C> void send(@Nonnull Member destination, @Nonnull CommandMessage<? extends C> command) throws Exception Sends the givencommandto the node assigned to handle messages with the givenroutingKey. The sender does not expect a reply. If this method throws an exception, the sender is guaranteed that the destination of the command did not receive it. If the method returns normally, the actual implementation of the connector defines the delivery guarantees. Connectors route the commands based on the givenroutingKey. Using the sameroutingKeywill result in the command being sent to the same member. Each message must be sent to exactly one member.- Parameters:
destination- The member of the network to send the message tocommand- The command to send to the (remote) member- Throws:
Exception- when an error occurs before or during the sending of the message
-
send
<C,R> void send(@Nonnull Member destination, @Nonnull CommandMessage<C> command, @Nonnull CommandCallback<? super C, R> callback) throws ExceptionSends the givencommandto the node assigned to handle messages with the givenroutingKey. The sender expect a reply, and will be notified of the result in the givencallback. If this method throws an exception, the sender is guaranteed that the destination of the command did not receive it. If the method returns normally, the actual implementation of the connector defines the delivery guarantees. Implementations should always invoke the callback with an outcome. If a member's connection was lost, and the result of the command is unclear, theCommandCallback.onResult(CommandMessage, CommandResultMessage)} method is invoked with aRemoteHandlingExceptiondescribing the failed connection. A client may choose to resend a command. Connectors route the commands based on the givenroutingKey. Using the sameroutingKeywill result in the command being sent to the same member.- Type Parameters:
C- The type of object expected as commandR- The type of object expected as result of the command- Parameters:
destination- The member of the network to send the message tocommand- The command to send to the (remote) membercallback- The callback- Throws:
Exception- when an error occurs before or during the sending of the message
-
subscribe
Registration subscribe(@Nonnull String commandName, @Nonnull MessageHandler<? super CommandMessage<?>> handler) Subscribes a command message handler for commands with givencommandName.- Parameters:
commandName- the command name. Usually this equals the fully qualified class name of the command.handler- the handler to subscribe- Returns:
- a handle that can be used to end the subscription
-
localSegment
Return anOptionalcontaining theCommandBuswhich is used by thisCommandBusConnectorto dispatch local and incomingCommandMessages on. It is highly recommended to implement this method to ensure an actual CommandBus is provided instead of a defaultOptional.empty().- Returns:
- an
Optionalcontaining theCommandBuswhich is used by thisCommandBusConnectorto dispatch local and incomingCommandMessages on
-
initiateShutdown
Initiate the shutdown of aCommandBusConnector.CommandMessages should no longer be dispatched after this method has been invoked.- Returns:
- a
CompletableFutureindicating when all previously sent commands are completed
-