feat: support retained-only flag in tedge mqtt sub#3494
feat: support retained-only flag in tedge mqtt sub#3494reubenmiller merged 2 commits intothin-edge:mainfrom
Conversation
Codecov ReportAttention: Patch coverage is
📢 Thoughts on this report? Let us know! 🚀 New features to boost your workflow:
|
didier-wenzek
left a comment
There was a problem hiding this comment.
Why not.
In practice, this command will behave as expected, but beware that retained messages are weird.
- There is no guarantee that all the retained messages are sent first on connect
- The retain flag is cleared for retained message updates.
Robot Results
|
Yes, though it seems that it is common behaviour (though maybe not in the spec). Or at least when using
Yes, this is the part which catches most new users out. The retained flag is only added to messages and sent to the client if the messages are retained on the MQTT broker prior to the client connecting. But if mosquitto_sub already offers it, then it seems to be more-or-less accepted. |
Yes. And, as long as you're aware of the lack of guarantees, it's really convenient. |
Signed-off-by: reubenmiller <reuben.d.miller@gmail.com>
20cba40 to
407c4de
Compare
|
Seems like this added a flaky test. I'll review the test to see how it can be made more reliable. |
79287b5 to
5cf240f
Compare
|
I was able to reproduce the flaky test locally, and tweak the testings to be more reliable. I suspect the root cause was the non-retained message was sometimes being published before the subscription was established. Now an additional sleep has been added before publishing the message. Before After |
Signed-off-by: reubenmiller <reuben.d.miller@gmail.com>
5cf240f to
75ac45f
Compare
Proposed changes
Adding support for the
--retained-onlyflag (same function as the mosquitto_sub flag of the same name), to allow users to only get the retained messages from the local MQTT broker.Note: When subscribing to the retained messages, it will only return the messages with the retain flag set, and it will actively stop when receiving the first non-retained message, or if the user specifies a duration timeout.
Below shows the most common usage of the flag.
tedge mqtt sub '#' --retained-only --duration 1sThe change will also allow the remaining usage of
mosquitto_subin the system tests to be replaced withtedge mqtt suband also providing a useful tool to users.Types of changes
Paste Link to the issue
Checklist
just prepare-devonce)just formatas mentioned in CODING_GUIDELINESjust checkas mentioned in CODING_GUIDELINESFurther comments