public class DefaultMQTT3Connection extends Object implements MQTT3Connection
MQTT3Connection| Modifier and Type | Field and Description |
|---|---|
static int |
ADDITIONAL_PROCESSING_TIME |
| Constructor and Description |
|---|
DefaultMQTT3Connection(String url,
String clientId,
MQTT3ConnectionOptions connectionOptions,
MQTT3FilePersistenceOptions filePersistenceOptions,
LWTMessage lwtMessage)
Returns an instance of a DefaultMQTT3Connection.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addSourceCallbackToConnectionLostHandler(org.mule.runtime.extension.api.runtime.source.SourceCallback<byte[],MQTT3MessageAttributes> callback)
Adds a
SourceCallback to the MQTT3ConnectionLostHandler. |
void |
connect()
Attempts to establish a connection to the mqtt broker.
|
void |
disconnect()
Closes the connection to the broker for this connection instance.
|
boolean |
equals(Object o) |
int |
hashCode() |
boolean |
isCleanSessionEnabled() |
boolean |
isConnected() |
boolean |
isSessionPresent() |
CompletableFuture<Integer> |
publish(String topic,
byte[] message,
int qos,
boolean isRetained)
Publishes a message to a topic, with the specified quality of service and retention flag.
|
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 be iterated over until a connection is successfully established.
|
void |
setTLSOptions(org.mule.runtime.api.tls.TlsContextFactory tlsContextFactory)
Sets a
TlsContextFactory for the connection. |
void |
setUsernamePassword(String username,
String password)
Sets a username and a password for authentication.
|
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)
Unsubscribes the client with the connection's client id from the provided list of
Topics. |
public static final int ADDITIONAL_PROCESSING_TIME
public DefaultMQTT3Connection(String url, String clientId, MQTT3ConnectionOptions connectionOptions, MQTT3FilePersistenceOptions filePersistenceOptions, LWTMessage lwtMessage) throws org.mule.runtime.api.connection.ConnectionException
url - the URL to connect to.clientId - the client id that identifies this connection.connectionOptions - an instance of MQTT3ConnectionOptionslwtMessage - an instance of LWTMessageorg.mule.runtime.api.connection.ConnectionExceptionpublic boolean isCleanSessionEnabled()
public void setUsernamePassword(String username, String password)
setUsernamePassword in interface MQTT3Connectionusername - the authentication username.password - the authentication password.public void setFailOverServers(String[] failOverServerArray)
setFailOverServers in interface MQTT3ConnectionfailOverServerArray - the list of servers to iterate over.public void connect()
throws org.mule.runtime.api.connection.ConnectionException
connect in interface MQTT3Connectionorg.mule.runtime.api.connection.ConnectionException - if connection attempt was unsuccessful.public 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.registerMessageHandler in interface MQTT3Connectiontopics - 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.public void subscribeToTopics(List<Topic> topics) throws org.mule.runtime.api.connection.ConnectionException
subscribeToTopics in interface MQTT3Connectiontopics - the list of Topic filters to subscribe to on the broker.org.mule.runtime.api.connection.ConnectionException - if an error occurs during subscription.public void unsubscribeListenerFromTopics(List<Topic> topics, MQTT3MessageHandler messageHandler)
Topics.
Removes the provided MQTT3MessageHandler from each of the Topic's callback list.unsubscribeListenerFromTopics in interface MQTT3Connectiontopics - the list of Topic filters from which the connection will be unsubscribed.messageHandler - a MQTT3MessageHandler to be removed from each of the Topic's callback list.public void addSourceCallbackToConnectionLostHandler(org.mule.runtime.extension.api.runtime.source.SourceCallback<byte[],MQTT3MessageAttributes> callback)
SourceCallback to the MQTT3ConnectionLostHandler.addSourceCallbackToConnectionLostHandler in interface MQTT3Connectionpublic boolean isConnected()
isConnected in interface MQTT3Connectionpublic boolean testConnectivity()
MQTT3ConnectiontestConnectivity in interface MQTT3Connectionpublic CompletableFuture<Integer> publish(String topic, byte[] message, int qos, boolean isRetained) throws MQTT3PublishException, org.mule.runtime.api.connection.ConnectionException
publish in interface MQTT3Connectiontopic - 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.isRetained - whether the message should be retained by the broker for the specified topic.CompletableFuture that returns the published message id on success.MQTT3PublishException - if an error occurred publishing the message to the broker.org.mule.runtime.api.connection.ConnectionException - if a connectivity issue occurred while publishing the message.public boolean isSessionPresent()
isSessionPresent in interface MQTT3Connectionpublic void setTLSOptions(org.mule.runtime.api.tls.TlsContextFactory tlsContextFactory)
throws org.mule.runtime.api.connection.ConnectionException
TlsContextFactory for the connection.setTLSOptions in interface MQTT3ConnectiontlsContextFactory - the TlsContextFactory with the required data.org.mule.runtime.api.connection.ConnectionExceptionpublic void disconnect()
disconnect in interface MQTT3ConnectionCopyright © 2025 MuleSoft, Inc.. All rights reserved.