Interface EventGateway

All Superinterfaces:
HasLocalHandlers
All Known Implementing Classes:
DefaultEventGateway

public interface EventGateway extends HasLocalHandlers
Gateway for publishing event messages to Flux Capacitor.

Events represent facts that have occurred and are typically used for downstream processing, projections, or integration with other systems. Unlike commands and queries, events are not expected to produce a response.

This gateway supports both local and remote event publishing. If local handlers are registered (via HasLocalHandlers.registerHandler(Object)), those will be invoked in-process. Otherwise, or in addition, the events are published to the Flux platform for delivery to interested consumers.

Note that publishing an event via this gateway does not associate it with an aggregate. If you're implementing an event-sourced aggregate, use Entity.apply(java.lang.Object...) instead to apply domain events to the aggregate and persist them in the event store.

See Also:
  • Method Details

    • publish

      default void publish(Object event)
      Publishes the given event object. If the object is not already a Message, it will be wrapped in one. The event is published with no delivery guarantee.

      If local handlers are registered, they will be invoked synchronously.

      Parameters:
      event - the event object to publish
      Throws:
      RuntimeException - if an error occurs during publishing
    • publish

      default void publish(Object payload, Metadata metadata)
      Publishes an event with the specified payload and metadata. The event is wrapped into a Message. The event is published with no delivery guarantee.

      If local handlers are registered, they will be invoked synchronously.

      Parameters:
      payload - the event payload
      metadata - the associated metadata
      Throws:
      RuntimeException - if an error occurs during publishing
    • publish

      CompletableFuture<Void> publish(Message message, Guarantee guarantee)
      Publishes the given Message to Flux Capacitor and/or local handlers. Returns a future that completes when the message has been fully processed or stored according to the given Guarantee.
      Parameters:
      message - the message to publish
      guarantee - the level of delivery guarantee to apply (e.g., store-before-acknowledge)
      Returns:
      a future that completes when the message has been handled
    • publish

      void publish(Object... messages)
      Publishes one or more event messages. Each message may be a raw payload or a Message instance. Events are published with no delivery guarantee.

      This method does not block for completion or acknowledgments.

      Parameters:
      messages - the events to publish
    • publish

      CompletableFuture<Void> publish(Guarantee guarantee, Object... messages)
      Publishes one or more event messages with a specific delivery guarantee. Each message may be a raw payload or a Message instance.

      Returns a future that completes when the messages have been handled or stored according to the specified Guarantee.

      Parameters:
      guarantee - the delivery guarantee (e.g., Guarantee.STORED)
      messages - the events to publish
      Returns:
      a future that completes upon publishing