MQTT5 shared subscriptions on broker restart

95 views
Skip to first unread message

Andrea

unread,
Dec 24, 2023, 5:10:59 AM12/24/23
to MQTT
Hi folks,
I'm implementing shared subscriptions on broker and despite the specification is clear when a shared subscription ceases to exist, I have troubles understanding what happens to the shared subscriptions when the broker restarts.
Those subscription aren't part of the session state but are part of the broker state.
Should be resilient to broker restarts?

Thanks for your effort in responses!
  Andrea

Greg Troxel

unread,
Dec 24, 2023, 8:31:07 AM12/24/23
to Andrea, MQTT
Andrea <selva...@gmail.com> writes:

> I'm implementing shared subscriptions on broker and despite the
> specification is clear when a shared subscription ceases to exist, I have
> troubles understanding what happens to the shared subscriptions when the
> broker restarts.
> Those subscription aren't part of the session state but are part of the
> broker state.
> Should be resilient to broker restarts?

Can you walk us through your analysis of the spec, in which sections it
talks about persisting state across broker restarts?

Without trying to read the spec, I would expect that a broker restart,
if persistence is implemented, should be like a network outage and the
clients reconnecting.

Andrea Selva

unread,
Dec 24, 2023, 10:39:20 AM12/24/23
to Greg Troxel, MQTT
Hi Greg 

On Sun, Dec 24, 2023 at 2:31 PM Greg Troxel <g...@lexort.com> wrote:
Andrea <selva...@gmail.com> writes:

> I'm implementing shared subscriptions on broker and despite the
> specification is clear when a shared subscription ceases to exist, I have
> troubles understanding what happens to the shared subscriptions when the
> broker restarts.
> Those subscription aren't part of the session state but are part of the
> broker state.
> Should be resilient to broker restarts?

Can you walk us through your analysis of the spec, in which sections it
talks about persisting state across broker restarts?

The specification doesn't speak about that, but I was wondering what happens to shared subscriptions if the broker for whatever reason is restarted.
The specification, in other parts, describes what is part of a stored session, like 4.1, if the broker is implementing the storage in a non-volatile memory then it's persistent.
So my first doubt is "should the shared subscription be stored" ?

Without trying to read the spec, I would expect that a broker restart,
if persistence is implemented, should be like a network outage and the
clients reconnecting.

In such a case, that would answer my question, that is "persist it and in a broker restart re-subscribe all the shared subscriptions that are still alive".

Thanks for answering
   Andrea

Hema M

unread,
Jan 3, 2024, 6:13:13 AMJan 3
to MQTT

To address this, you have two options. You can either set cleansession to false, keeping your session information on the server until the final disconnect (note that the session information may linger), or you can handle your subscriptions in the OnConnect handler. The latter ensures that subscriptions are reestablished every time you are connected, even when autoreconnect is in action.

If maintaining consistent subscriptions is a priority for your application, utilizing the OnConnect() callback to handle subscriptions ensures that it is triggered every time the client is reconnected. Hope my answer helps!!

Reply all
Reply to author
Forward
0 new messages