MQTT

Allows publishing events through MQTT, ideal for IoT and lightweight streaming

Overview

MQTT is a lightweight, publish-subscribe protocol ideal for machine-to-machine communication in IoT environments.

Joule leverages MQTT to publish events through an MQTT publisher, allowing communication between devices and services over specified topics.

Examples & DSL attributes

This example configures an MQTT publisher to send events to the mydevice/leaf topic.

The events are published as compressed JSON, using QoS level 1 for reliable delivery.

The publisher connects with the client ID myClientId, username lyndon and tenant uk to the broker at tcp://127.0.0.1:1883. Security is handled with a JWT claim using RSA encryption, with a private key stored in file2.

mqttPublisher:
  clientId: myClientId
  username: lyndon
  tenant: uk
  topic: mydevice/leaf
  qos: 1
  broker: tcp://127.0.0.1:1883

  serializer:
    compress: true

  security:
    jwtclaim:
      audienceId: projectID
      keyFile: file2
      algorithm: RSA
      isPrivateKey: true

Attributes schema

Serialisation attributes schema

Serialiser example

In this example, the MQTT publisher is configured to serialise StreamEvents as compressed JSON payloads.

The compress setting is enabled to reduce the size of the data and batch is set to false, meaning events are sent individually rather than in batches.

mqttPublisher:
  ...

  serializer:
    compress: true
    batch: false

Last will attributes schema

These attributes provide the configuration parameters to send publisher disconnection notifications to connected subscribers.

Last will example

In this example, the last will feature is configured for the MQTT publisher.

It specifies that if the publisher disconnects unexpectedly, a message will be sent to the topic usecasename/status/failure to notify subscribers of the disconnection.

The message will indicate that the Joule MQTT process disconnected from broker and the publisher will wait for a delay of 15 seconds before sending this notification.

mqttPublisher:
  ...

  last will:
    topic: usecasename/status/failure
    message: "Joule MQTT process disconnected from broker"
    interval delay: 15

Additional resources

Last updated