Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [mosquitto-dev] persistent_client_expiration, async connections with libmosquitto, and topic subscriptions

Steve Prior <sprior@xxxxxxxxxxxx> wrote:
> So far I've posted two questions here and haven't received any
> response whatsoever, don't know if I'm asking bad questions - I
> hope not.
> Previously I started with the assumption that I've started a
> mosquitto connection with clean_session=true with an async
> connection, then called mosquitto_loop_start().
> I had noticed that in the event that the broker unexpectedly
> disconnects a connection it appears that libmosquitto will
> attempt to reconnect. Since I had used clean_session=true it
> also appears that any existing subscriptions will be lost (am I
> correct in this???) which means that a client with
> subscriptions will need to set an on_disconnect callback not to
> reconnect, but to resubscribe to previous subscriptions. This
> seems a little odd to me if correct that the library tries to
> be so helpful about re-establishing the connection but then
> requires manual intervention to resubscribe.

You normally subscribe in the on_connect callback. You can't do
anything in the on_disconnect callback.

I'm not really sure I agree with it being odd. You get
reconnected, but subscriptions are based on your own plans and
methods. Remember, you can dynamically subscribe and unsusbcribe
at will, it's not just once at connect time, though that's often
what people do.

If you want clean session, you get clean session, that means no
subscriptions. Easiest way for you is to subscribe in the
on_connect callback.

If you don't want a clean session, you don't have to resubscribe
(ever, really, except you have to do it once, so you'll often see
it in the on_connect callback too) but you also have to be
prepared to receive queued messages received while you were

Whether you want clean session or not is really, entirely up to

Karl Palsson

Attachment: OpenPGP-digital-signature.html
Description: OpenPGP Digital Signature

Back to the top