1.6 KiB
1.6 KiB
title | nav_order |
---|---|
CloudEvents MQTT | 5 |
MQTT Support
The SDK supports both V3 and V5 MQTT binding specifications via these Java client libraries:
- Paho
- HiveMQ
NOTE: MQTT V3 only supports structured mode transfer of CloudEVents. Operations related to binary mode transmission are either not available or will throw runtime exceptions if an attempt is made to use them.
Both client library implementations rely on a provided maven dependency.
General Usage
There is a slight variance in usage between the two supported client libraries owing to the way those clients have implemented support for the two versions of MQTT but the general pattern is the same as every other protocol binding.
Creating a message from a CloudEvent
- Obtain a
MessageWriter
from a factory. - Use the writer to populate the MQTT message using structured or binary mode.
mqttMessage = messageWriter.writeBinary(cloudEvent);
or,mqttMessage = messageWriter.writeStructured(cloudEvent, eventFormat);
Creating a CloudEvent from a message.
- Obtain a 'MessageReader' from a message factory for an MQTT message.
- Obtain a CloudEvent from the reader.
- CloudEvent cloudEvent = reader.toEvent();
PAHO Client Usage
Maven
<dependency>
<groupId>io.cloudevents</groupId>
<artifactId>cloudevents-mqtt-paho</artifactId>
<version>2.x.y</version>
</dependency>
HiveMQ Client Usage
Maven
<dependency>
<groupId>io.cloudevents</groupId>
<artifactId>cloudevents-mqtt-hivemq</artifactId>
<version>2.x.y</version>
</dependency>