Interface CommandGateway

All Superinterfaces:
HasLocalHandlers
All Known Implementing Classes:
DefaultCommandGateway

public interface CommandGateway extends HasLocalHandlers
Gateway interface for publishing command messages in Flux Capacitor.

Commands represent intent—typically something that should change state in the application. They are handled by command handlers (annotated with HandleCommand) and may yield results or raise validation errors.

This gateway supports fire-and-forget invocation as well as synchronous and asynchronous sending of commands with or without results. Commands may be published as raw payloads or wrapped Message objects.

Implementations of this interface may also invoke local handlers when available, as exposed via HasLocalHandlers.

See Also:
  • Method Details

    • sendAndForget

      void sendAndForget(Object command)
      Sends a command without waiting for a result.
      Parameters:
      command - the command to send
    • sendAndForget

      void sendAndForget(Object payload, Metadata metadata)
      Sends a command with metadata without waiting for a result.
      Parameters:
      payload - the command payload
      metadata - metadata to include
    • sendAndForget

      void sendAndForget(Object payload, Metadata metadata, Guarantee guarantee)
      Sends a command with metadata and delivery guarantee, without waiting for a result.
      Parameters:
      payload - the command payload
      metadata - metadata to include
      guarantee - the delivery guarantee (e.g., stored before ack)
    • sendAndForget

      void sendAndForget(Object... messages)
      Sends multiple commands without waiting for results.
      Parameters:
      messages - the commands to send
    • sendAndForget

      CompletableFuture<Void> sendAndForget(Guarantee guarantee, Object... messages)
      Sends multiple commands with a delivery guarantee without waiting for results.
      Parameters:
      guarantee - the delivery guarantee
      messages - the commands to send
      Returns:
      a future that completes when all commands have been sent
    • send

      <R> CompletableFuture<R> send(Object command)
      Sends a command and returns a future for the result.
      Type Parameters:
      R - the expected result type
      Parameters:
      command - the command to send
      Returns:
      a future with the command's result
    • send

      <R> CompletableFuture<R> send(Object payload, Metadata metadata)
      Sends a command with metadata and returns a future for the result.
      Type Parameters:
      R - the expected result type
      Parameters:
      payload - the command payload
      metadata - metadata to include
      Returns:
      a future with the command's result
    • sendForMessage

      CompletableFuture<Message> sendForMessage(Message message)
      Sends a fully-formed Message and returns a future for the result Message.
      Parameters:
      message - the message to send
      Returns:
      a future with the result message
    • send

      <R> List<CompletableFuture<R>> send(Object... messages)
      Sends multiple commands and returns futures for their results.
      Type Parameters:
      R - the expected result type
      Parameters:
      messages - the commands to send
      Returns:
      a list of futures with each command's result
    • sendForMessages

      List<CompletableFuture<Message>> sendForMessages(Message... messages)
      Sends multiple messages and returns futures for the result messages.
      Parameters:
      messages - the messages to send
      Returns:
      a list of futures with the resulting messages
    • sendAndWait

      <R> R sendAndWait(Object command)
      Sends a command and waits for the result.
      Type Parameters:
      R - the expected result type
      Parameters:
      command - the command to send
      Returns:
      the result of the command
    • sendAndWait

      <R> R sendAndWait(Object payload, Metadata metadata)
      Sends a command with metadata and waits for the result.
      Type Parameters:
      R - the expected result type
      Parameters:
      payload - the command payload
      metadata - metadata to include
      Returns:
      the result of the command
    • send

      <R> CompletableFuture<R> send(Request<R> query)
      Sends a typed request command and returns a future for the result.
      Type Parameters:
      R - the result type
      Parameters:
      query - the request command
      Returns:
      a future with the command's result
    • send

      <R> CompletableFuture<R> send(Request<R> payload, Metadata metadata)
      Sends a typed request command with metadata and returns a future for the result.
      Type Parameters:
      R - the result type
      Parameters:
      payload - the request command
      metadata - metadata to include
      Returns:
      a future with the command's result
    • sendAndWait

      <R> R sendAndWait(Request<R> query)
      Sends a typed request command and waits for the result.
      Type Parameters:
      R - the result type
      Parameters:
      query - the request command
      Returns:
      the result of the command
    • sendAndWait

      <R> R sendAndWait(Request<R> payload, Metadata metadata)
      Sends a typed request command with metadata and waits for the result.
      Type Parameters:
      R - the result type
      Parameters:
      payload - the request command
      metadata - metadata to include
      Returns:
      the result of the command
    • close

      void close()
      Shuts down the command gateway.