org.mule.modules

mule-module-mqtt

config

Namespacehttp://www.mulesoft.org/schema/mule/mqtt
Schema Locationhttp://www.mulesoft.org/schema/mule/mqtt/current/mule-mqtt.xsd  (View Schema)
Schema Version1.0
Minimum Mule Version3.3.0

Module Overview

Mule MQTT Module.

Summary

Configuration
<mqtt:config>
Configure an instance of this module
Message Sources
<mqtt:subscribe>
Subscribe to a single or multiple topic filters.
Message Processors
<mqtt:publish>
Publish a message to a topic.

Configuration

To use the this module within a flow the namespace to the module must be included. The resulting flow will look similar to the following:

<mule xmlns="http://www.mulesoft.org/schema/mule/core"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xmlns:mqtt="http://www.mulesoft.org/schema/mule/mqtt"
      xsi:schemaLocation="
               http://www.mulesoft.org/schema/mule/core
               http://www.mulesoft.org/schema/mule/core/current/mule.xsd
               http://www.mulesoft.org/schema/mule/mqtt
               http://www.mulesoft.org/schema/mule/mqtt/current/mule-mqtt.xsd">

      <!-- here goes your flows and configuration elements -->

</mule>

This module is configured using the config element. This element must be placed outside of your flows and at the root of your Mule application. You can create as many configurations as you deem necessary as long as each carries its own name.

Each message processor, message source or transformer carries a config-ref attribute that allows the invoker to specify which configuration to use.

Attributes
TypeNameDefault ValueDescriptionJava TypeMIME TypeEncoding
xs:string name Optional. Give a name to this configuration so it can be later referenced.
xs:string brokerServerUri tcp://localhost:1883 Optional. MQTT broker server URI.
xs:boolean cleanSession true Optional. Clean Session.
xs:int connectionTimeout 30 Optional. Connection Timeout.
xs:int keepAliveInterval 60 Optional. Keep-alive interval.
xs:string lwtMessage Optional. Last Will and Testimate message.
xs:int lwtQos 2 Optional. Last Will and Testimate QOS.
xs:boolean lwtRetained false Optional. Last Will and Testimate retention.
xs:string lwtTopicName Optional. Last Will and Testimate Topic
xs:string password Optional. Password to log into broker with.
xs:string persistenceLocation Optional. Directory on the machine where message persistence can be stored to disk.
xs:string username Optional. Username to log into broker with.

Example

INCLUDE_ERROR

Example

INCLUDE_ERROR

Connection Pool

This connector offers automatic connection management via the use of a connection pool. The pool will act a storage mechanism for all the connections that are in-use by the user of this connector.

Prior to execution of a processor, the connector will attempt to lookup an already established connection and if one doesn't exists it will create one. That lookup mechanism is done in the connection pool via the use of connection variables declared as keys.

The user of the connector can configure the pool by adding a connection-pooling-profile to the connector configuration like this:

    <mqtt:connection-pooling-profile maxActive="10" maxIdle="10"
                             exhaustedAction="WHEN_EXHAUSTED_GROW" maxWait="120" minEvictionMillis="60000" evictionCheckIntervalMillis="30000"/>

The following is a list of connection attributes, each connection attribute can be configured at the config element level or they can also be added to each processor. If they are used at the processor level they get the benefit of full expression resolution.

Connection Attributes
NameDefault ValueDescriptionJava TypeMIME TypeEncoding
config-ref Optional. Specify which configuration to use.
clientId Client identifier for the broker. String */* UTF-8

Reconnection Strategies

Reconnection Strategies specify how a connector behaves when its connection fails. You can control how Mule attempts to reconnect by specifying a number of criteria:

With a reconnection strategy, you can better control the behavior of a failed connection, by configuring it, for example, to re-attempt the connection only once every 15 minutes, and to give up after 30 attempts. You can also send an automatic notification to your IT administrator whenever this reconnection strategy goes into effect. You can even define a strategy that attempts to reconnect only during business hours. Such a setting can prove useful if your server is frequently shut down for nightly maintenance.

Configuration

A reconnection strategy that allows the user to configure how many times a reconnection should be attempted and how long to wait between attempts.

    <mqtt:config>
         <reconnect count="5" frequency="1000"/>
    </mqtt:config>
Reconnect Attributes
NameDefault ValueDescription
frequency 2000 Optional. How often (in ms) to reconnect
count 2 Optional. How many reconnection attempts to make

For more information about reconnection strategies in Mule, or even how to write your own custom reconnection strategy please check this section.

Message Processors

<mqtt:publish>

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.

XML Sample
INCLUDE_ERROR

XML Sample
INCLUDE_ERROR

Attributes
NameDefault ValueDescriptionJava TypeMIME TypeEncoding
config-ref Optional. Specify which configuration to use.
topicName Topic to publish message to. String */* UTF-8
waitForCompletionTimeOut Optional. Time in milliseconds to wait for the delivery to occur. Long */*
qos AT_LEAST_ONCE Optional. QoS level to use when publishing message. MqttConnector.DeliveryQoS */*
messagePayload The payload that will be published over MQTT. byte */*
muleEvent The in-flight MuleEvent. MuleEvent */*
Connection Parameters
This are only required if you didn't specified them at the configuration element. They are also useful for overriding the values of the configurations or even if you need to extract them from the Mule message since they support expression evaluation.
clientId Optional. Client identifier for the broker. String */* UTF-8
Returns
Return Type Description
byte[] the byte[] that was published.
Exception Payloads
Payload ClassDescription
MqttException thrown if the MQTT publish fails.

Message Sources

<mqtt:subscribe>

Subscribe to a single or multiple topic filters.

XML Sample
INCLUDE_ERROR

XML Sample
INCLUDE_ERROR

Attributes
NameDefault ValueDescriptionJava TypeMIME TypeEncoding
config-ref Optional. Specify which configuration to use.
topicFilter Optional. Single topic filter to subscribe to. String */* UTF-8
qos AT_LEAST_ONCE Optional. QoS level to use when subscribing to a single topic. MqttConnector.DeliveryQoS */*
callback The SourceCallback used by Mule to dispatch the received messages. SourceCallback */*
Connection Parameters
This are only required if you didn't specified them at the configuration element. They are also useful for overriding the values of the configurations or even if you need to extract them from the Mule message since they support expression evaluation.
clientId Optional. Client identifier for the broker. String */* UTF-8
Child Elements
NameDefault ValueDescriptionJava Type
<mqtt:topic-subscriptions> Optional. A List of MqttTopicSubscription to subscribe to. List<MqttTopicSubscription>
Exception Payloads
Payload ClassDescription
ConnectionException thrown if the MQTT subscribe fails.

Transformers