4

I currently have a Mosquitto MQTT Broker on which some IoT Nodes publish their information on a specific topic. I have an instance of Telegraf from InfluxData running that subscribes to this topic and stores the information into InfluxDB.

Requirements:

I understand that the information once published on a topic will be sent out immediately to the subscriber from the Broker. I am looking for a retention or caching mechanism in MQTT Broker which can wait till there are X number of datapoints on the topic that are published and then sent to the Subscriber.

Is there such a mechanism that exists in standard MQTT Brokers or does this go beyond the MQTT Standard?

7

No, this is not possible with a MQTT broker.

There are 2 situations where a broker will cache a message on a given topic.

  1. When a message is published with the retained bit set. This message will be stored and delivered to any client that subscribed to a matching topic before any new messages. This is a single message per topic and a new message with the retained bit will replace any current message.

  2. If a client has a persistent subscription and is offline, the broker will queue all messages sent while it is offline to deliver when it reconnects (unless it sets the cleanSession bit to true in it's connection packet)

The only way to achieve what you describe is to have another client batch up the messages and publish the collection on a different topic.

EDIT:

The MQTTv5 spec supports setting a Message Expiry Interval value on a message.

If present, the Four Byte value is the lifetime of the Application Message in seconds. If the Message Expiry Interval has passed and the Server has not managed to start onward delivery to a matching subscriber, then it MUST delete the copy of the message for that subscriber [MQTT-3.3.2-5].

If absent, the Application Message does not expire.

The PUBLISH packet sent to a Client by the Server MUST contain a Message Expiry Interval set to the received value minus the time that the Application Message has been waiting in the Server [MQTT-3.3.2-6]. Refer to section 4.1 for details and limitations of stored state.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.