Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Retain MQTT client id #3001

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

williamthome
Copy link
Contributor

Description

Adds the possibility to subscribe into model/sessionStorage/post/mqtt-origin-client-id topic.
The only changed thing is the { retain: true } option.

Checklist

  • documentation updated
  • tests added
  • no BC breaks

@mworrell mworrell requested a review from mmzeeman June 3, 2022 19:47
@mworrell mworrell added this to the 1.0 milestone Jun 3, 2022
Copy link
Member

@mmzeeman mmzeeman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the intended effect of this change? The sessionStorage model also stores the client id.

Ah.. being able to subscribe to the the id is nice. Maybe we should make this more explicit by publishing it retained to the $bridge\origin\client-id instead of doing it indirectly via the sessionStorage. What do you think @mworrell

@williamthome
Copy link
Contributor Author

The motivation for this is to get notified immediately after a custom worker connects.
Without the retain option I could not receive the client id because the topic model/sessionStorage/post/mqtt-origin-client-id fires before a custom worker can handle the event.

@mworrell
Copy link
Member

Retained in $bridge/origin/client-id sounds good to me, it is the client-id of that bridge.

@williamthome
Copy link
Contributor Author

williamthome commented Jun 10, 2022

@mmzeeman @mworrell could you check if I understood the proposed changes?

@mmzeeman
Copy link
Member

mmzeeman commented Jun 13, 2022

What I wanted to prevent was that you need to know the location of the client-id of the bridge and get it from some session storage topic. It was a bit strange for me to also use retained messages to the session storage model post calls.

With this change the client-id is now stored in two locations. One as retained message, and second in the session storage. That is probably not a good idea.

Is it possible to just store it just as a retained message? And maybe move this before the code which publishes the client id?

cotonic.broker.call("model/sessionStorage/get/mqtt-origin-client-id")
. That should then become a subscribe.

It is probably a bit tricky with respect to race conditions during reconnects.

What do you think @mworrell?

@mworrell
Copy link
Member

Maybe we could add a small broker function to do a retained value lookup?

Then we can remove the session storage of client-id.

@mmzeeman
Copy link
Member

I was thinking about that too.. What would also possible/handy is an add an option to subscribe on which the callback is immediately notified, also when there are no retained messages. But the retained value lookup is simpler I think.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants