public class DefaultMQTT3Connection extends Object implements MQTT3Connection
MQTT3Connection| 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 |
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 |
setConnectionLostHandler(MQTT3ConnectionLostHandler mqtt3ConnectionLostHandler)
Sets a
MQTT3ConnectionLostHandler to be invoked when connection is lost. |
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 |
subscribeListenerToTopics(List<Topic> topics,
MQTT3MessageHandler messageHandler)
Subscribes the client with the connection's client id to the provided list of
Topics. |
void |
unsubscribeListenerFromTopics(List<Topic> topics,
MQTT3MessageHandler messageHandler)
Unsubscribes the client with the connection's client id from the provided list of
Topics. |
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
org.mule.runtime.api.connection.ConnectionException - if connection attempt was unsuccessful.public void subscribeListenerToTopics(List<Topic> topics, MQTT3MessageHandler messageHandler) throws org.mule.runtime.api.connection.ConnectionException
Topics.
Associates the provided MQTT3MessageHandler to each of the subscribed topics.subscribeListenerToTopics in interface MQTT3Connectiontopics - the list of Topic filters to which the connection will be subscribed.messageHandler - a MQTT3MessageHandler to be called when a message is received for one of the subscribed topics.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 setConnectionLostHandler(MQTT3ConnectionLostHandler mqtt3ConnectionLostHandler)
MQTT3ConnectionLostHandler to be invoked when connection is lost.setConnectionLostHandler in interface MQTT3Connectionmqtt3ConnectionLostHandler - the MQTT3ConnectionLostHandler to be called when connection is lost.public boolean isConnected()
isConnected 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 © 2023 MuleSoft, Inc.. All rights reserved.