Class Mqtt5MessagePublisher

java.lang.Object
org.mockserver.async.publish.Mqtt5MessagePublisher
All Implemented Interfaces:
MessagePublisher

public class Mqtt5MessagePublisher extends Object implements MessagePublisher
A MessagePublisher that delegates to an MQTT v5 MqttClient. The channel name maps directly to an MQTT topic.

Compared with MqttMessagePublisher (v3.1.1), MQTT 5 adds user properties: PublishOptions.getHeaders() (e.g. correlation-ID headers) are delivered as MQTT 5 user properties, so header-location correlation IDs — which cannot be carried over MQTT 3 — work here. QoS (0/1/2), retain, and binary payloads are supported as in v3.

  • Constructor Details

    • Mqtt5MessagePublisher

      public Mqtt5MessagePublisher(String brokerUrl, String clientId)
      Create a v5 publisher connected to the given broker with default QoS (1) and no security.
    • Mqtt5MessagePublisher

      public Mqtt5MessagePublisher(String brokerUrl, String clientId, int qos)
      Create a v5 publisher connected to the given broker with a specific QoS and no security.
    • Mqtt5MessagePublisher

      public Mqtt5MessagePublisher(String brokerUrl, String clientId, int qos, MqttSecurity security)
      Create a v5 publisher with optional security configuration.
      Parameters:
      brokerUrl - the MQTT broker URL (e.g. tcp://localhost:1883 or ssl://localhost:8883)
      clientId - the client identifier
      qos - the MQTT QoS level (0, 1, or 2)
      security - security configuration (may be null for plaintext)
  • Method Details

    • publish

      public void publish(String channel, String payload)
      Description copied from interface: MessagePublisher
      Publish the given payload to the specified channel with no key or headers.
      Specified by:
      publish in interface MessagePublisher
      Parameters:
      channel - the channel / topic name
      payload - the message payload (typically JSON)
    • publish

      public void publish(String channel, String payload, PublishOptions options)
      Publish with per-message options from AsyncAPI bindings. Applies QoS and retain when present, and delivers PublishOptions.getHeaders() as MQTT 5 user properties.
      Specified by:
      publish in interface MessagePublisher
      Parameters:
      channel - the channel / topic name
      payload - the message payload (typically JSON)
      options - per-message publish options (may be null)
    • publishBytes

      public void publishBytes(String channel, byte[] payload)
      Publish a binary payload with no options.
    • getQos

      public int getQos()
      Returns:
      the configured QoS level for this publisher
    • close

      public void close()
      Description copied from interface: MessagePublisher
      Release any resources held by this publisher (producer connections, etc.).
      Specified by:
      close in interface MessagePublisher