Class IncomingCommandInvoker

java.lang.Object
io.axoniq.framework.springcloud.command.IncomingCommandInvoker

public class IncomingCommandInvoker extends Object
Turns a 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 Details

    • IncomingCommandInvoker

      public IncomingCommandInvoker(Supplier<String> memberName, @Nullable MessageConverter converter)
      Constructs an IncomingCommandInvoker reporting failures as originating from the member the given memberName supplies.

      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 on
      converter - the converter attached to received commands for inline payload conversion, and used to serialize application-specific exception details, or null when none is available
  • Method Details

    • bind

      public void bind(CommandBusConnector.Handler handler)
      Binds the handler that incoming commands are to be invoked on, replacing any previously bound one.

      Called by the connector when DistributedCommandBus registers its handler through CommandBusConnector.onIncomingCommand(CommandBusConnector.Handler).

      Parameters:
      handler - the handler to invoke incoming commands on
    • handle

      Handles the given request, 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