Question about retain message management

31 views
Skip to first unread message

Nicolas Jouanin

unread,
Jul 21, 2015, 3:36:56 PM7/21/15
to mq...@googlegroups.com
Hi,
I have a question concerning the management of retain messages by a broker.
[MQTT-3.3.1-5] says when a client publish a message with retains flag set, that Server MUST store the Application Message and its QoS, so that it can be delivered to future subscribers whose subscriptions match its topic name.
Should the server store this message globally, i.e.. store only the last messages received from any client on each topic, or should its store last messages received per session, ie. store last retained messages received from each client on each topic ?

Nicholas O'Leary

unread,
Jul 21, 2015, 4:07:25 PM7/21/15
to mq...@googlegroups.com
Hi, 

It is per topic, not per client session. When a client subscribes to a topic, it receives the most recent retained message on that topic regardless of which client published it.

Nick




--
To learn more about MQTT please visit http://mqtt.org
---
You received this message because you are subscribed to the Google Groups "MQTT" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mqtt+uns...@googlegroups.com.
To post to this group, send email to mq...@googlegroups.com.
Visit this group at http://groups.google.com/group/mqtt.
For more options, visit https://groups.google.com/d/optout.

Nicolas Jouanin

unread,
Jul 21, 2015, 4:11:52 PM7/21/15
to mq...@googlegroups.com
OK, so each new message received with RETAIN flag replaces any previous message (may be sent from another client) received on that topic.
One more thing I don’t completely understand is the difference between [MQTT-3.3.1-7] (discard retained message on QOS_0) and [MQTT-3.3.1-10] (discard retain on empty payload)

Nicholas O'Leary

unread,
Jul 21, 2015, 4:24:41 PM7/21/15
to mq...@googlegroups.com
MQTT-3.3.1-10 describes a mechanism by which any client can clear a retained message on a topic (RETAIN flag set, 0-length payload).

MQTT-3.3.1-7 is covering the case where brokers are not required to persist QoS 0 messages and what that means for QoS 0 retained messages. 
A broker SHOULD store the message, but as is consistent with other QoS 0 messages, the broker is permitted to discard the message if it finds it needs to, in which case there will no longer be a retained message on the topic.

Hope that clarifies it.

Nicolas Jouanin

unread,
Jul 21, 2015, 4:31:57 PM7/21/15
to mq...@googlegroups.com
Hi,

Thanks for your reply. 
This is more or less what I understood and how i’ve written my broker implementation. It happens that conformance test with paho are failing and I was told (on paho-dev mailing-list) that it may be due to retain messages not correctly cleared. I needed first to be sure I understood the spec. correctly.
I’ll check my code now.

Karl Palsson

unread,
Jul 21, 2015, 9:20:51 PM7/21/15
to mq...@googlegroups.com
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

"Nicholas O'Leary" <nick....@gmail.com> wrote:
> MQTT-3.3.1-7 is covering the case where brokers are not required to
> persist
> QoS 0 messages and what that means for QoS 0 retained messages.
> A broker SHOULD store the message, but as is consistent with other QoS 0
> messages, the broker is permitted to discard the message if it finds it
> needs to, in which case there will no longer be a retained message on
> the
> topic.
>
> Hope that clarifies it.


wat? I hadn't ever noticed that one. So, retain is _optional_ for qos
0? I guess this "makes sense" if you consider that qos 0 doesn't have
an ack, so a "conforming" broker could just ignore all qos0 messages too
right? "did my best, sorry that wasn't good enough"

I would consider this to be extremely surprising if I found that retain
didn't retain, are there any brokers that actually did this?

Sincerely,
Karl P

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)

iQIcBAEBAgAGBQJVru+mAAoJEBmotQ/U1cr289UP/3E0df6gbtnJb4FAB3GTW+Gb
R8uHcUE/7yE8XDlUykdagLRpcMz/kWPd1y6US3kMyw9lfU7qt0Vz9zctVQAIrVp0
hI+uBhK2yrX0GBjJo1tCxIocOcCbQeaNe8PrgF5h/3nUWvkdmK36HJVSZwLpLLkL
LHLCFO19aHKyXln8KakwX5//LokbqzZubewpKDq44vEUiTphRFT3eU9MZ/9CSmOJ
KM0IBoqCO66aWpgH8MOe2KAs97NWzW1ewsxQmYhHOqEmPIygW6HSuPdm/sV2vJ+o
Cv0VIe6Ei3mHQXeY1LiGCH5NUQ7/HFHVo/VC1apzcooexkZxXW88HMi6tajh4NSF
aNNosWYbu3EA3XQZ83tRh5egA7ER0GMiQGbcTWP5ZK8WIyetwtOHr9p53JrwdJ4X
BkiqQOTxh6nk6ls9veO/t2mGREO4XD4vr8cZ+GQHbVM23ZnrF8aMmdUWPDi1PXJ4
ILGaLtNbsvzhN6/WhO849h2vBobiPHG7N20os3DuVWs1B1+/cX7F8XVT1mWc9aRc
QkFEMsm/fuOHhE02clh0FYu5Fj09MsPYurB/l0EEKdCKP5wAP0OKpVm5iCVBh+f7
OFc5uvVZpiolF5AYk0URWW6dUZF9G7xcLMryu69to4G/VfEp7MfVOyRWh25rJInp
mfNrgzT7H2BS/Jw9XiFZ
=Gu7w
-----END PGP SIGNATURE-----

Nicholas O'Leary

unread,
Jul 22, 2015, 2:58:55 AM7/22/15
to mq...@googlegroups.com

Strictly speaking it is optional, but the broker SHOULD store them just as any other QoS message.

I don't know of any brokers that explicitly don't retain qos0 messages. There may be brokers that, if you restart the broker, qos0 messages are forgotten about as they were only held in memory... that would be within the requirements of the spec.

Nick


Reply all
Reply to author
Forward
0 new messages