Package org.mockserver.async.subscribe
Class MqttMessageSubscriber
java.lang.Object
org.mockserver.async.subscribe.MqttMessageSubscriber
- All Implemented Interfaces:
MessageSubscriber
A
MessageSubscriber that uses an MQTT MqttClient to subscribe
to topics and record received messages.
Recorded messages are stored in a bounded BoundedMessageStore per channel
to prevent unbounded memory growth.
-
Constructor Summary
ConstructorsConstructorDescriptionMqttMessageSubscriber(String brokerUrl, String clientId) Create a subscriber connected to the given MQTT broker with no security.MqttMessageSubscriber(String brokerUrl, String clientId, int qos) Create a subscriber with a specific QoS level and no security.MqttMessageSubscriber(String brokerUrl, String clientId, int qos, int maxRecordedMessages) Create a subscriber with a specific QoS level and recorded-message cap, no security.MqttMessageSubscriber(String brokerUrl, String clientId, int qos, int maxRecordedMessages, MqttSecurity security) Create a 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).voidStart subscribing to the given channel.voidunsubscribe(String channel) Stop subscribing to the given channel.
-
Constructor Details
-
MqttMessageSubscriber
Create a subscriber connected to the given MQTT broker with no security. Backward-compatible entry point.- Parameters:
brokerUrl- the MQTT broker URL (e.g.tcp://localhost:1883)clientId- the client identifier
-
MqttMessageSubscriber
Create a subscriber with a specific QoS level and no security. -
MqttMessageSubscriber
Create a subscriber with a specific QoS level and recorded-message cap, no security. Backward-compatible entry point. -
MqttMessageSubscriber
public MqttMessageSubscriber(String brokerUrl, String clientId, int qos, int maxRecordedMessages, MqttSecurity security) Create a subscriber 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)maxRecordedMessages- maximum recorded messages per channelsecurity- security configuration (may be null for plaintext)
-
-
Method Details
-
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
-