Class IncomingCommandInvoker
CommandDispatchRequest received from another member into an invocation of this application's local
command handler, and its outcome back into a CommandDispatchReply.
This invoker exists as a component of its own, separate from
SpringCloudCommandController, for two reasons. It breaks what would otherwise be a construction cycle: the
controller is a Spring bean created before the connector, while the handler it
must invoke only becomes available once DistributedCommandBus registers one on the connector, later still.
The connector binds the handler here when it receives it. It also keeps
the whole receiving path testable without standing up a web stack — the controller that remains is nothing but an
HTTP mapping.
A request that arrives before a handler is bound is answered with a
CommandErrorCode.NO_HANDLER_FOR_COMMAND reply rather than an HTTP error. The dispatching member then sees a
transient NoHandlerForCommandException, which is exactly the
situation: this member is still starting up, and will be able to handle the command shortly.
- Since:
- 5.4.0
- Author:
- Allard Buijze
-
Constructor Summary
ConstructorsConstructorDescriptionIncomingCommandInvoker(Supplier<String> memberName, @Nullable MessageConverter converter) Constructs anIncomingCommandInvokerreporting failures as originating from the member the givenmemberNamesupplies. -
Method Summary
Modifier and TypeMethodDescriptionvoidbind(CommandBusConnector.Handler handler) Binds thehandlerthat incoming commands are to be invoked on, replacing any previously bound one.handle(CommandDispatchRequest request) Handles the givenrequest, received from another member of the cluster.
-
Constructor Details
-
IncomingCommandInvoker
Constructs anIncomingCommandInvokerreporting failures as originating from the member the givenmemberNamesupplies.Taken as a supplier because a member is not named until it has registered with discovery, which happens after this invoker is built. Resolving it per failure reports the name this member is actually known by, rather than the provisional one it had at start-up.
- Parameters:
memberName- supplies the name identifying this application in replies it sends, used to point at the member a failure originated onconverter- the converter attached to received commands for inline payload conversion, and used to serialize application-specific exception details, ornullwhen none is available
-
-
Method Details
-
bind
Binds thehandlerthat incoming commands are to be invoked on, replacing any previously bound one.Called by the connector when
DistributedCommandBusregisters its handler throughCommandBusConnector.onIncomingCommand(CommandBusConnector.Handler).- Parameters:
handler- the handler to invoke incoming commands on
-
handle
Handles the givenrequest, received from another member of the cluster.The returned future always completes successfully: a failure while handling the command is reported in the reply, not as a failed future, so the controller can answer with it.
- Parameters:
request- the request received from another member- Returns:
- a future completing with the reply to send back
-