public class

MqttConnector

extends Object
implements MuleContextAware
java.lang.Object
   ↳ org.mule.modules.mqtt.MqttConnector
Known Direct Subclasses
Known Indirect Subclasses

Class Overview

Mule MQTT Module.

{@sample.config INCLUDE_ERROR}

{@sample.config INCLUDE_ERROR}

Summary

Nested Classes
enum MqttConnector.DeliveryQoS  
Constants
String MQTT_DEFAULT_BROKER_URI
String MQTT_DEFAULT_QOS_STRING
String MQTT_DELIVERY_TOKEN_VARIABLE
String MQTT_PROPERTIES_PREFIX
String MQTT_QOS_PROPERTY
String MQTT_TOPIC_NAME_PROPERTY
Fields
private static final Log LOGGER
public static final MqttConnector.DeliveryQoS MQTT_DEFAULT_QOS
private String brokerServerUri MQTT broker server URI.
private boolean cleanSession Clean Session.
private MqttClient client
private String clientId
private MqttConnectOptions connectOptions
private int connectionTimeout Connection Timeout.
private int keepAliveInterval Keep-alive interval.
private String lwtMessage Last Will and Testimate message.
private int lwtQos Last Will and Testimate QOS.
private boolean lwtRetained Last Will and Testimate retention.
private String lwtTopicName Last Will and Testimate Topic
private MuleContext muleContext
private String password Password to log into broker with.
private String persistenceLocation Directory on the machine where message persistence can be stored to disk.
private String username Username to log into broker with.
Public Constructors
MqttConnector()
Public Methods
void connect(String clientId)
Connects the MQTT client.
void disconnect()
Disconnects the client.
String getActiveClientId()
Connection Identifier
String getBrokerServerUri()
int getConnectionTimeout()
int getKeepAliveInterval()
String getLwtMessage()
int getLwtQos()
String getLwtTopicName()
MqttClient getMqttClient()
MuleContext getMuleContext()
String getPassword()
String getPersistenceLocation()
String getUsername()
boolean isCleanSession()
boolean isConnected()
Are we connected
boolean isLwtRetained()
byte[] publish(String topicName, Long waitForCompletionTimeOut, MqttConnector.DeliveryQoS qos, byte[] messagePayload, MuleEvent muleEvent)
Publish a message to a topic.
void setBrokerServerUri(String brokerServerUri)
void setCleanSession(boolean cleanSession)
void setConnectionTimeout(int connectionTimeout)
void setKeepAliveInterval(int keepAliveInterval)
void setLwtMessage(String lwtMessage)
void setLwtQos(int lwtQos)
void setLwtRetained(boolean lwtRetained)
void setLwtTopicName(String lwtTopicName)
void setMuleContext(MuleContext muleContext)
void setPassword(String password)
void setPersistenceLocation(String persistenceLocation)
void setUsername(String username)
void subscribe(String topicFilter, MqttConnector.DeliveryQoS qos, List<MqttTopicSubscription> topicSubscriptions, SourceCallback callback)
Subscribe to a single or multiple topic filters.
[Expand]
Inherited Methods
From class java.lang.Object
From interface org.mule.api.context.MuleContextAware

Constants

public static final String MQTT_DEFAULT_BROKER_URI

Constant Value: "tcp://localhost:1883"

private static final String MQTT_DEFAULT_QOS_STRING

Constant Value: "AT_LEAST_ONCE"

public static final String MQTT_DELIVERY_TOKEN_VARIABLE

Constant Value: "mqtt.deliveryToken"

public static final String MQTT_PROPERTIES_PREFIX

Constant Value: "mqtt"

public static final String MQTT_QOS_PROPERTY

Constant Value: "mqtt.qos"

public static final String MQTT_TOPIC_NAME_PROPERTY

Constant Value: "mqtt.topicName"

Fields

private static final Log LOGGER

public static final MqttConnector.DeliveryQoS MQTT_DEFAULT_QOS

private String brokerServerUri

MQTT broker server URI.

private boolean cleanSession

Clean Session.

private MqttClient client

private String clientId

private MqttConnectOptions connectOptions

private int connectionTimeout

Connection Timeout.

private int keepAliveInterval

Keep-alive interval.

private String lwtMessage

Last Will and Testimate message.

private int lwtQos

Last Will and Testimate QOS.

private boolean lwtRetained

Last Will and Testimate retention.

private String lwtTopicName

Last Will and Testimate Topic

private MuleContext muleContext

private String password

Password to log into broker with.

private String persistenceLocation

Directory on the machine where message persistence can be stored to disk.

private String username

Username to log into broker with.

Public Constructors

public MqttConnector ()

Public Methods

public void connect (String clientId)

Connects the MQTT client.

Parameters
clientId Client identifier for the broker.
Throws
ConnectionException

public void disconnect ()

Disconnects the client.

Throws
MqttException

public String getActiveClientId ()

Connection Identifier

public String getBrokerServerUri ()

public int getConnectionTimeout ()

public int getKeepAliveInterval ()

public String getLwtMessage ()

public int getLwtQos ()

public String getLwtTopicName ()

public MqttClient getMqttClient ()

public MuleContext getMuleContext ()

public String getPassword ()

public String getPersistenceLocation ()

public String getUsername ()

public boolean isCleanSession ()

public boolean isConnected ()

Are we connected

public boolean isLwtRetained ()

public byte[] publish (String topicName, Long waitForCompletionTimeOut, MqttConnector.DeliveryQoS qos, byte[] messagePayload, MuleEvent muleEvent)

Publish a message to a topic. If sucessful a flow variable named MQTT_DELIVERY_TOKEN_VARIABLE will contain the MqttDeliveryToken that can be used for further awaiting completion.

Parameters
topicName Topic to publish message to.
waitForCompletionTimeOut Time in milliseconds to wait for the delivery to occur.
qos QoS level to use when publishing message.
messagePayload The payload that will be published over MQTT.
muleEvent The in-flight MuleEvent.
Returns
  • the byte[] that was published.
Throws
MqttException thrown if the MQTT publish fails.

public void setBrokerServerUri (String brokerServerUri)

Parameters
brokerServerUri

public void setCleanSession (boolean cleanSession)

Parameters
cleanSession

public void setConnectionTimeout (int connectionTimeout)

Parameters
connectionTimeout

public void setKeepAliveInterval (int keepAliveInterval)

Parameters
keepAliveInterval

public void setLwtMessage (String lwtMessage)

Parameters
lwtMessage

public void setLwtQos (int lwtQos)

Parameters
lwtQos

public void setLwtRetained (boolean lwtRetained)

Parameters
lwtRetained

public void setLwtTopicName (String lwtTopicName)

Parameters
lwtTopicName

public void setMuleContext (MuleContext muleContext)

Parameters
muleContext

public void setPassword (String password)

Parameters
password

public void setPersistenceLocation (String persistenceLocation)

Parameters
persistenceLocation

public void setUsername (String username)

Parameters
username

public void subscribe (String topicFilter, MqttConnector.DeliveryQoS qos, List<MqttTopicSubscription> topicSubscriptions, SourceCallback callback)

Subscribe to a single or multiple topic filters.

Parameters
topicFilter Single topic filter to subscribe to.
qos QoS level to use when subscribing to a single topic.
topicSubscriptions A List of MqttTopicSubscription to subscribe to.
callback The SourceCallback used by Mule to dispatch the received messages.
Throws
ConnectionException thrown if the MQTT subscribe fails.