Package org.mockserver.async.publish
Class MqttMessagePublisher
java.lang.Object
org.mockserver.async.publish.MqttMessagePublisher
- All Implemented Interfaces:
MessagePublisher
A
MessagePublisher that delegates to an MQTT MqttClient.
The channel name maps directly to an MQTT topic.
Supports configurable QoS (0, 1, or 2) and both text and binary payloads.
-
Constructor Summary
ConstructorsConstructorDescriptionMqttMessagePublisher(String brokerUrl, String clientId) Create a publisher connected to the given MQTT broker with default QoS (1) and no security.MqttMessagePublisher(String brokerUrl, String clientId, int qos) Create a publisher connected to the given MQTT broker with a specific QoS and no security.MqttMessagePublisher(String brokerUrl, String clientId, int qos, MqttSecurity security) Create a publisher connected to the given MQTT broker 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 a message with per-message options from AsyncAPI bindings.voidpublishBytes(String channel, byte[] payload) Publish a binary payload to the given channel.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
-
MqttMessagePublisher
Create a publisher connected to the given MQTT broker with default QoS (1) and no security. Backward-compatible entry point.- Parameters:
brokerUrl- the MQTT broker URL (e.g.tcp://localhost:1883)clientId- the client identifier
-
MqttMessagePublisher
Create a publisher connected to the given MQTT broker with a specific QoS and no security. Backward-compatible entry point.- Parameters:
brokerUrl- the MQTT broker URL (e.g.tcp://localhost:1883)clientId- the client identifierqos- the MQTT QoS level (0, 1, or 2)
-
MqttMessagePublisher
Create a publisher connected to the given MQTT broker with optional security configuration.- Parameters:
brokerUrl- the MQTT broker URL (e.g.ssl://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 a message with per-message options from AsyncAPI bindings. AppliesPublishOptions.getQos()andPublishOptions.getRetain()when non-null; falls back to the instance-level QoS and no-retain defaults. The Kafkakeyfield is ignored for MQTT.MQTT does not support message-level headers; when
PublishOptions.getHeaders()is non-empty, a DEBUG log is emitted noting that header-location correlation IDs are not delivered over MQTT. Payload-location correlation IDs are unaffected (they are injected into the payload before publishing).- Specified by:
publishin interfaceMessagePublisher- Parameters:
channel- the MQTT topic namepayload- the message payload (typically JSON)options- per-message publish options (may be null)
-
publishBytes
Publish a binary payload to the given channel. Supports binary message formats as specified in AsyncAPI channel bindings.- Parameters:
channel- the MQTT topic namepayload- the raw binary payload
-
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
-