JMS clients and MQTT clients can share the same Topic destinations when they are run simultaneously. Messages published by MQTT/JMS clients are automatically converted to suit JMS/MQTT consumers.

MQTT Publish packets with QOS levels 1 or 2 are treated as JMS messages with delivery mode set to Persistent mode and follow the same semantics of a Persistent JMS Message. When an MQTT Publisher sends a packet to the FioranoMQ Server, depending on the QOS level, it is stored into the Topic destination and forwarded to the corresponding subscribers.

Case 1

MQTT Publisher publishes on to a Topic destination which has a JMS Subscriber subscribed to it. The MQTT Packet will be sent in the form of JMS BytesMessage to the JMS Subscriber after constructing a BytesMessage with MQTT Publish packet as its payload.

Case 2

JMS Publisher publishes a JMS Message on to a Topic destination which has an MQTT Subscriber. The JMS message is converted to an MQTT Publish packet before delivering it to the MQTT Subscriber. Contents such as Message properties and body are dumped to the payload of the MQTT Publish packet. Therefore, MQTT client Consumers must be aware of the origin of packets it can receive and read the payload accordingly.

If an MQTT Subscriber receives a JMS Message in the form of MQTT Publish Packet, it must therefore assume that the first four bytes in the payload indicate the number of message properties followed by key-value pairs; and then the size of data followed by the data part.

Writing Fiorano MQTT Clients

Fiorano's MQTT client libraries are available in Java language as of 10.2.0 version. This section illustrates an example to Publish/Subscribe MQTT packets and various methods to be used to write their own application.

FioranoMqttClient is a lightweight client communicating to an MQTT Server using its methods and implements the interface IFioranoMqttClient. Following are the jars required for the MQTT client:

  • mqttpackets-impl.jar
  • mqtttransport-impl.jar
  • mqttutil-impl.jar

An instance of FioranoMqttClient class can be fetched using its static method 'getFioranoMqttClient'.

Following publisher code creates an MQTT connection and publishes MQTT Publish Packet with various parameters set.

Publisher Code Sample

Following Subscriber Code creates a Subscriber and consumes packets.

Subscriber Code Sample
Adaptavist ThemeBuilder EngineAtlassian Confluence