MQTT integration

Details about how Qlik Sense can use Butler to send pub-sub messages using MQTT.

What is MQTT?

MQTT is a light weight publish-subscribe (“pub-sub”) protocol.

Used in both the telecomms industry and various Internet of Things applications, there are client libraries available for many different languages and platforms. This is important, as there is a good chance other systems can find a way of sending MQTT messages, which Butler can then listen for/subscribe to.

Outgoing MQTT from Butler itself

If MQTT is enabled, Butler will forward events (reload failed, user opened a session to Sense etc) to MQTT. These events are sent to the MQTT topics defined in the Butler.mqttConfig section of Butler’s config file.

Outgoing MQTT - publish

Butler can post messages to MQTT topics. The /v4/mqttpublishmessage API endpoint is used for this.
This way Butler can send status information and notifications to other systems, outside of Qlik Sense. Use cases include:

  • Notify downstream systems that Sense has finished creating some data set that the downstream system depends on.

  • Send debug or trace messages to MQTT instead of to the Sense log. Using a MQTT client (there are multiple ones on both Windows, OSX and Linux) you can then monitor the messages in real time. Very useful during development of tricky Sense load scripts!

  • Start Sense tasks (typically reloads) from the Sense load script. Very useful when you need to trigger a second app reload once the first app’s load script reaches some specific point of execution.
    This way the scheduling and execution of Sense tasks can be made much more flexible than using the built in QMC scheduler.

    Note: While possible to start reload tasks using MQTT, it’s usually easier to do this using Butler’s REST API.

  • Send messages to platforms such as Node-RED. Node-RED is an open source platform (with a graphical editor) intended for integrating different systems and data sources. As it is built on there are many different modules available, offering integrations with all sorts of systems and protocols.
    Using Node.RED together with Qlik Sense and Butler, it is possible to interface with social media from the Sense load script (send a Tweet when some condition occur during app reload, for example).

Incoming MQTT - subscribe

Butler subscribes to all MQTT messages in the topic specied in the confif file property Butler.mqttConfig.subscriptionRootTopic.
Which in MQTT lingo means “listen to all messages in the this topic, as well as in any subtopics”.

When Butler gets a message as a result of this subscription it is analysed and if the topic matches any of the predefined topics with special meaning, the associated tasks are carried out.

Topics with special meaning are:

  • Start Sense task. The exact topic is defined in config property Butler.mqttConfig.taskStartTopic.
    Note that this topic must be a subtopic to the topic specified in Butler.mqttConfig.subscriptionRootTopic!
    Starts the Sense task identified by the ID sent in the message body. More info in the examples section.

As Butler listens to all messages in the topic tree specified by Butler.mqttConfig.subscriptionRootTopic it can easily be extended with handlers for additional topics.