public interface MQTT3Connection
| Modifier and Type | Method and Description |
|---|---|
void |
addSourceCallbackToConnectionLostHandler(org.mule.runtime.extension.api.runtime.source.SourceCallback<byte[],MQTT3MessageAttributes> callback) |
void |
connect()
Establishes the connection to the MQTT broker.
|
void |
disconnect()
Perform client disconnect.
|
boolean |
isConnected() |
boolean |
isSessionPresent() |
CompletableFuture<Integer> |
publish(String topic,
byte[] message,
int qos,
boolean retained)
Publishes a message to an mqtt topic.
|
void |
registerMessageHandler(List<Topic> topics,
MQTT3MessageHandler messageHandler)
Registers a
MQTT3MessageHandler locally for the provided topics without subscribing to the broker. |
void |
setFailOverServers(String[] failOverServerArray)
Sets a list of fail-over servers to iterate over and attempt to establish a connection.
|
void |
setTLSOptions(org.mule.runtime.api.tls.TlsContextFactory tlsContextFactory)
Sets the TLS context for the connection.
|
void |
setUsernamePassword(String username,
String password)
Sets the username and password for the connection to authenticate to the mqtt broker.
|
void |
subscribeToTopics(List<Topic> topics)
Subscribes to the provided topics on the broker.
|
boolean |
testConnectivity()
Tests if the connection can be established without changing the current connection state.
|
void |
unsubscribeListenerFromTopics(List<Topic> topics,
MQTT3MessageHandler messageHandler)
De-registers the provided
MQTT3MessageHandler from the list of provided topics. |
void registerMessageHandler(List<Topic> topics, MQTT3MessageHandler messageHandler)
MQTT3MessageHandler locally for the provided topics without subscribing to the broker.
This allows handlers to be ready before connecting to prevent race conditions.topics - the list of Topic filters for which the handler will be registered.messageHandler - a MQTT3MessageHandler to be called when messages for these topics are received.void subscribeToTopics(List<Topic> topics) throws org.mule.runtime.api.connection.ConnectionException
topics - the list of Topic filters to subscribe to on the broker.org.mule.runtime.api.connection.ConnectionException - if an error occurs during subscription.void connect()
throws org.mule.runtime.api.connection.ConnectionException
org.mule.runtime.api.connection.ConnectionException - if connection attempt was unsuccessful.void unsubscribeListenerFromTopics(List<Topic> topics, MQTT3MessageHandler messageHandler)
MQTT3MessageHandler from the list of provided topics.
For the topics which have no remaining MQTT3MessageHandler associated, the connection will
unsubscribe.topics - the list of Topic filters for which the MQTT3MessageHandler will be removed.messageHandler - the MQTT3MessageHandler will be removed.CompletableFuture<Integer> publish(String topic, byte[] message, int qos, boolean retained) throws MQTT3PublishException, org.mule.runtime.api.connection.ConnectionException
topic - the topic to which the message should be published.message - the message content to be sent.qos - the quality of service with which the message should be published.retained - whether the message should be retained by the broker.CompletableFuture that will return the messageId of the published message on success.MQTT3PublishException - if the publish operation fails.org.mule.runtime.api.connection.ConnectionException - if a connectivity error arises during publish.void setTLSOptions(org.mule.runtime.api.tls.TlsContextFactory tlsContextFactory)
throws org.mule.runtime.api.connection.ConnectionException
tlsContextFactory - the TlsContextFactory with the required data.org.mule.runtime.api.connection.ConnectionExceptionvoid setUsernamePassword(String username, String password)
username - the authentication username.password - the authentication password.void setFailOverServers(String[] failOverServerArray)
failOverServerArray - the list of servers to iterate over.boolean isSessionPresent()
boolean isConnected()
boolean testConnectivity()
throws org.mule.runtime.api.connection.ConnectionException
org.mule.runtime.api.connection.ConnectionException - if the connection cannot be established.void addSourceCallbackToConnectionLostHandler(org.mule.runtime.extension.api.runtime.source.SourceCallback<byte[],MQTT3MessageAttributes> callback)
void disconnect()
Copyright © 2025 MuleSoft, Inc.. All rights reserved.