Interface MessagePublisher

All Known Implementing Classes:
AmqpMessagePublisher, KafkaAvroMessagePublisher, KafkaMessagePublisher, Mqtt5MessagePublisher, MqttMessagePublisher

public interface MessagePublisher
Publishes a message payload to a named channel (topic).

Implementations exist for Kafka (KafkaMessagePublisher) and MQTT (MqttMessagePublisher).

  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Release any resources held by this publisher (producer connections, etc.).
    default void
    Block until every message published so far has been acknowledged by the broker, throwing if any of them failed to be delivered.
    void
    publish(String channel, String payload)
    Publish the given payload to the specified channel with no key or headers.
    default void
    publish(String channel, String key, String payload, Map<String,String> headers)
    Publish the given payload with an optional key and headers.
    default void
    publish(String channel, String payload, PublishOptions options)
    Publish the given payload with per-message options derived from AsyncAPI bindings.
  • Method Details

    • publish

      void publish(String channel, String payload)
      Publish the given payload to the specified channel with no key or headers.
      Parameters:
      channel - the channel / topic name
      payload - the message payload (typically JSON)
    • publish

      default void publish(String channel, String key, String payload, Map<String,String> headers)
      Publish the given payload with an optional key and headers. Default implementation delegates to publish(String, String), ignoring key and headers — implementations that support them override this.
      Parameters:
      channel - the channel / topic name
      key - the message key (may be null)
      payload - the message payload (typically JSON)
      headers - optional headers (may be null)
    • publish

      default void publish(String channel, String payload, PublishOptions options)
      Publish the given payload with per-message options derived from AsyncAPI bindings. Default implementation delegates to publish(String, String), ignoring the options — implementations that support them override this.
      Parameters:
      channel - the channel / topic name
      payload - the message payload (typically JSON)
      options - per-message publish options (may be null)
    • flush

      default void flush()
      Block until every message published so far has been acknowledged by the broker, throwing if any of them failed to be delivered.

      Implementations that send asynchronously (notably Kafka) would otherwise let a caller report a successful publish before the broker has accepted — or rejected — the message. Callers that report publish success to a user must call this first.

      The default implementation is a no-op, for publishers that deliver synchronously.

      Throws:
      RuntimeException - if any message published since the last flush failed to deliver
    • close

      void close()
      Release any resources held by this publisher (producer connections, etc.).