@RestController @RequestMapping(value="/spring-command-bus-connector") public class SpringHttpCommandBusConnector extends Object implements CommandBusConnector
CommandBusConnector
implementation based on Spring Rest characteristics. Serves as a RestController
to receive Command Messages for its node, but also contains a RestOperations
component to send Command
Messages to other nodes. Will use a localCommandBus
of type CommandBus
to publish any received
Command Messages to its local instance. Messages are de-/serialized using a Serializer
.Modifier and Type | Class and Description |
---|---|
class |
SpringHttpCommandBusConnector.SpringHttpReplyFutureCallback<C,R> |
Constructor and Description |
---|
SpringHttpCommandBusConnector(CommandBus localCommandBus,
org.springframework.web.client.RestOperations restOperations,
Serializer serializer)
Initialize a
SpringHttpCommandBusConnector using the provided local CommandBus ,
RestOperations and Serializer . |
SpringHttpCommandBusConnector(CommandBus localCommandBus,
org.springframework.web.client.RestOperations restOperations,
Serializer serializer,
Executor executor)
Initialize a
SpringHttpCommandBusConnector using the provided local CommandBus ,
RestOperations , Serializer and Executor . |
Modifier and Type | Method and Description |
---|---|
<C,R> CompletableFuture<?> |
receiveCommand(SpringHttpDispatchMessage<C> dispatchMessage) |
Registration |
registerHandlerInterceptor(MessageHandlerInterceptor<? super CommandMessage<?>> handlerInterceptor)
Register the given
handlerInterceptor . |
<C> void |
send(Member destination,
CommandMessage<? extends C> commandMessage)
Sends the given
command to the node assigned to handle messages with the given
routingKey . |
<C,R> void |
send(Member destination,
CommandMessage<C> commandMessage,
CommandCallback<? super C,R> callback)
Sends the given
command to the node assigned to handle messages with the given
routingKey . |
Registration |
subscribe(String commandName,
MessageHandler<? super CommandMessage<?>> handler)
Subscribes a command message handler for commands with given
commandName . |
public SpringHttpCommandBusConnector(CommandBus localCommandBus, org.springframework.web.client.RestOperations restOperations, Serializer serializer)
SpringHttpCommandBusConnector
using the provided local CommandBus
,
RestOperations
and Serializer
. The localCommandBus
is used to publish received commands
which to the local segment. The given RestOperations provides the connectivity between other nodes to send
commands, and the Serializer is used to serialize the command messages when they are sent between nodes.
The Executor
used to make the sending of commands asynchronous is defaulted to a
DirectExecutor.INSTANCE
.localCommandBus
- the CommandBus
to publish received commands which to the local segmentrestOperations
- the RestOperations
used to send commands to other nodesserializer
- the Serializer
used to serialize command messages when they are sent between nodespublic SpringHttpCommandBusConnector(CommandBus localCommandBus, org.springframework.web.client.RestOperations restOperations, Serializer serializer, Executor executor)
SpringHttpCommandBusConnector
using the provided local CommandBus
,
RestOperations
, Serializer
and Executor
. The localCommandBus
is used to publish
received commands which to the local segment. The given RestOperations provides the connectivity between other
nodes to send commands, and the Serializer is used to serialize the command messages when they are sent between
nodes. The provided Executor is used to unblock then sending of a command with the RestOperations.localCommandBus
- the CommandBus
to publish received commands which to the local segmentrestOperations
- the RestOperations
used to send commands to other nodesserializer
- the Serializer
used to serialize command messages when they are sent between nodesexecutor
- the Executor
used to make the sending of commands using the @link RestOperations}
asynchronouspublic <C> void send(Member destination, CommandMessage<? extends C> commandMessage)
CommandBusConnector
command
to the node assigned to handle messages with the given
routingKey
. 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 given routingKey
. Using the same routingKey
will result in the command being sent to the same member. Each message must be sent to exactly one
member.send
in interface CommandBusConnector
destination
- The member of the network to send the message tocommandMessage
- The command to send to the (remote) memberpublic <C,R> void send(Member destination, CommandMessage<C> commandMessage, CommandCallback<? super C,R> callback)
CommandBusConnector
command
to the node assigned to handle messages with the given
routingKey
. The sender expect a reply, and will be notified of the result in the given
callback
.
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, the CommandCallback.onFailure(org.axonframework.commandhandling.CommandMessage, Throwable)
method is invoked with a
RemoteCommandHandlingException
describing
the failed connection. A client may choose to resend a command.
Connectors route the commands based on the given routingKey
. Using the same routingKey
will result in the command being sent to the same member.send
in interface CommandBusConnector
C
- The type of object expected as commandR
- The type of object expected as result of the commanddestination
- The member of the network to send the message tocommandMessage
- The command to send to the (remote) membercallback
- The callbackpublic Registration subscribe(String commandName, MessageHandler<? super CommandMessage<?>> handler)
CommandBusConnector
commandName
.subscribe
in interface CommandBusConnector
commandName
- the command name. Usually this equals the fully qualified class name of the command.handler
- the handler to subscribe@PostMapping(value="/command") public <C,R> CompletableFuture<?> receiveCommand(@RequestBody SpringHttpDispatchMessage<C> dispatchMessage)
public Registration registerHandlerInterceptor(MessageHandlerInterceptor<? super CommandMessage<?>> handlerInterceptor)
MessageHandlerInterceptorSupport
handlerInterceptor
. After registration, the interceptor will be invoked for each
handled Message on the messaging component that it was registered to, prior to invoking the message's handler.registerHandlerInterceptor
in interface MessageHandlerInterceptorSupport<CommandMessage<?>>
handlerInterceptor
- The interceptor to registerCopyright © 2010–2018. All rights reserved.