Interface ResultGateway

All Known Implementing Classes:
DefaultResultGateway, WebResponseGateway

public interface ResultGateway
Gateway interface for sending result messages in response to a command or query.

The ResultGateway is used internally by Flux Capacitor to publish the result of a request, such as a command or query, back to the requester. Each response must specify the target (usually a client ID) and a request ID to correlate the result with the original request.

Responses can be sent as raw payloads or wrapped in a Message. Optionally, metadata and a Guarantee can be supplied to control how delivery is handled.

Note: The results of handler methods—such as HandleCommand or HandleQuery methods—are automatically published to the ResultGateway. This interface is typically only used directly when you want to manually complete a request at a later time, such as after receiving a third-party callback or performing asynchronous processing unrelated to the original handler method.

Example use case: Handling a payment gateway callback that matches a previously submitted command request.

See Also:
  • Method Details

    • respond

      default CompletableFuture<Void> respond(Object response, String target, Integer requestId)
      Sends a response message with default metadata and Guarantee.NONE.

      If the provided response is a Message, its payload and metadata are extracted and used directly. Otherwise, the response is wrapped as a new Message.

      Parameters:
      response - the response object or Message to be sent
      target - the recipient of the response (typically a client ID)
      requestId - the unique ID of the original request
      Returns:
      a CompletableFuture that completes when the message is published (depending on the guarantee)
    • respond

      CompletableFuture<Void> respond(Object payload, Metadata metadata, String target, Integer requestId, Guarantee guarantee)
      Sends a response with the specified payload, metadata, target, request ID, and delivery guarantee.

      This method gives full control over how and when the response is delivered.

      Parameters:
      payload - the payload of the response
      metadata - additional metadata to include
      target - the intended recipient of the response
      requestId - the identifier of the original request
      guarantee - delivery guarantee (e.g., Guarantee.SENT or Guarantee.STORED)
      Returns:
      a CompletableFuture that completes when the response is dispatched (depending on the guarantee)