Package org.mockserver.async.publish
Class Mqtt5MessagePublisher
java.lang.Object
org.mockserver.async.publish.Mqtt5MessagePublisher
- All Implemented Interfaces:
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 Summary
ConstructorsConstructorDescriptionMqtt5MessagePublisher(String brokerUrl, String clientId) Create a v5 publisher connected to the given broker with default QoS (1) and no security.Mqtt5MessagePublisher(String brokerUrl, String clientId, int qos) Create a v5 publisher connected to the given broker with a specific QoS and no security.Mqtt5MessagePublisher(String brokerUrl, String clientId, int qos, MqttSecurity security) Create a v5 publisher with optional security configuration. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Release any resources held by this publisher (producer connections, etc.).intgetQos()voidPublish the given payload to the specified channel with no key or headers.voidpublish(String channel, String payload, PublishOptions options) Publish with per-message options from AsyncAPI bindings.voidpublishBytes(String channel, byte[] payload) Publish a binary payload with no options.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.mockserver.async.publish.MessagePublisher
publish
-
Constructor Details
-
Mqtt5MessagePublisher
Create a v5 publisher connected to the given broker with default QoS (1) and no security. -
Mqtt5MessagePublisher
Create a v5 publisher connected to the given broker with a specific QoS and no security. -
Mqtt5MessagePublisher
Create a v5 publisher with optional security configuration.- Parameters:
brokerUrl- the MQTT broker URL (e.g.tcp://localhost:1883orssl://localhost:8883)clientId- the client identifierqos- the MQTT QoS level (0, 1, or 2)security- security configuration (may be null for plaintext)
-
-
Method Details
-
publish
Description copied from interface:MessagePublisherPublish the given payload to the specified channel with no key or headers.- Specified by:
publishin interfaceMessagePublisher- Parameters:
channel- the channel / topic namepayload- the message payload (typically JSON)
-
publish
Publish with per-message options from AsyncAPI bindings. Applies QoS and retain when present, and deliversPublishOptions.getHeaders()as MQTT 5 user properties.- Specified by:
publishin interfaceMessagePublisher- Parameters:
channel- the channel / topic namepayload- the message payload (typically JSON)options- per-message publish options (may be null)
-
publishBytes
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:MessagePublisherRelease any resources held by this publisher (producer connections, etc.).- Specified by:
closein interfaceMessagePublisher
-