Package org.mockserver.async.subscribe
Class Mqtt5MessageSubscriber
java.lang.Object
org.mockserver.async.subscribe.Mqtt5MessageSubscriber
- All Implemented Interfaces:
MessageSubscriber
A
MessageSubscriber that uses an MQTT v5 MqttClient to
subscribe to topics and record received messages — the v5 counterpart of
MqttMessageSubscriber.
MQTT 5 user properties on incoming messages are recorded as the
RecordedMessage headers (MQTT 3 has no equivalent). Recorded messages are
stored in a bounded BoundedMessageStore per channel to prevent unbounded
memory growth.
-
Constructor Summary
ConstructorsConstructorDescriptionMqtt5MessageSubscriber(String brokerUrl, String clientId) Create a v5 subscriber connected to the given broker with no security.Mqtt5MessageSubscriber(String brokerUrl, String clientId, int qos) Create a v5 subscriber with a specific QoS and no security.Mqtt5MessageSubscriber(String brokerUrl, String clientId, int qos, int maxRecordedMessages, MqttSecurity security) Create a v5 subscriber with optional security configuration. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Clear all recorded messages and stop all subscriptions.Return all messages recorded across all channels.getRecordedMessages(String channel) Return all messages recorded on the given channel since subscription started (or since the last reset).booleanReturnsfalseif the MQTT callback has reported a disconnect.voidStart subscribing to the given channel.voidunsubscribe(String channel) Stop subscribing to the given channel.
-
Constructor Details
-
Mqtt5MessageSubscriber
Create a v5 subscriber connected to the given broker with no security. -
Mqtt5MessageSubscriber
Create a v5 subscriber with a specific QoS and no security. -
Mqtt5MessageSubscriber
public Mqtt5MessageSubscriber(String brokerUrl, String clientId, int qos, int maxRecordedMessages, MqttSecurity security) Create a v5 subscriber with optional security configuration.- Parameters:
brokerUrl- the MQTT broker URLclientId- the client identifierqos- the MQTT QoS level (0, 1, or 2)maxRecordedMessages- maximum recorded messages per channelsecurity- security configuration (may be null for plaintext)
-
-
Method Details
-
isHealthy
public boolean isHealthy()Returnsfalseif the MQTT callback has reported a disconnect. -
subscribe
Description copied from interface:MessageSubscriberStart subscribing to the given channel. Messages will be recorded internally and are retrievable viaMessageSubscriber.getRecordedMessages(String).- Specified by:
subscribein interfaceMessageSubscriber- Parameters:
channel- the channel/topic to subscribe to
-
unsubscribe
Description copied from interface:MessageSubscriberStop subscribing to the given channel.- Specified by:
unsubscribein interfaceMessageSubscriber
-
getRecordedMessages
Description copied from interface:MessageSubscriberReturn all messages recorded on the given channel since subscription started (or since the last reset).- Specified by:
getRecordedMessagesin interfaceMessageSubscriber
-
getAllRecordedMessages
Description copied from interface:MessageSubscriberReturn all messages recorded across all channels.- Specified by:
getAllRecordedMessagesin interfaceMessageSubscriber
-
close
public void close()Description copied from interface:MessageSubscriberClear all recorded messages and stop all subscriptions.- Specified by:
closein interfaceMessageSubscriber
-