MQTT Source Integration

MQTT is commonly used as a means of exchanging streaming data. Vantiq includes direct support for reading MQTT data streams. The essence of the integration is as follows:

MQTT Source Representation

A source resource defines the integration with a specific MQTT stream and contains the following properties:

Create an MQTT Source

The following example illustrates how to create an MQTT source using the REST API. MQTT sources can also be defined in Modelo by using the Add button to select Source… when in Modelo Development Mode.

POST https://dev.vantiq.com/api/v1/resources/sources
{ 
    "name": "myMqttSource",
    "type": "MQTT",
    "direction": "BOTH",
    "config": {
        "serverURI": "tcp://me.vantiq.com:1883",
        "topics": ["com.accessg2.stream.mqtt.example"],
        "keepAliveInterval": 30,
        "connectionTimeout": 30,
        "cleanSession": true,
    }
}

Delete an MQTT Source

The example MQTT source named myMqttSource can be deleted using the REST API by issuing the following request:

POST https://dev.vantiq.com/api/v1/resources/sources/myMqttSource

Publish Notifications via MQTT

Notifications are produced by the rules system when PUBLISH is called as a rule action. The PUBLISH request for MQTT sources takes three parameters: the message object to send and the source and topic to which the publish is sent. For example:

PUBLISH { message: { data: "somedata" }} TO SOURCE someMQTTSource 
  USING { topic: "the.mqtt.topic" }