I’ve installed the MQTT binding and configured a broker connection and a generic MQTT thing. Maybe I missed something, but I cannot find any configuration settings for having a persistent session for a topic subscription.
For my intended application, that is counting deltas send by one of my IOT devices, I do not want to miss any messages while openHAB is not able to receive. Either because openHAB is down or the connection is broken.
My setup is:
- Platform information:
- Hardware: x86_64/16GB RAM
- OS: Docker engine 20.10.8 under Linux Ubuntu 20.04
- openHAB version: 3.1.0
The sender can direct that its messages are retained at the broker.
A new subscriber will get the last message sent.
I don’t think there’s any way to get the last N messages.
There is. At least on the MQTT specification part and it is called persistent session. The client does so by setting the “clean session” flag to false, when connecting to the broker.
The broker then stores the session state on behalf of the client and tracks which messages the client has already seen and which are still to be send (consumed) to the client. The flag is part of the
CONNACK messages of the MQTT protocol.
For this reason a client implementation should manage a “clean session” attribute for the connection settings to be put into the
Using a persistent session in combination with the QOS settings of 1 or 2 guarantees, that the client never misses any messages produced by the publisher.