Skip to content

Conversation

@rbino
Copy link

@rbino rbino commented May 5, 2020

Allow checking if a given SubscriberID has an existing session

Allow checking if a given SubscriberID has an existing session
@ioolkos
Copy link
Contributor

ioolkos commented May 5, 2020

Hi Riccardo :)
Thanks, let's see what we need to check here:

  • does it do what it says it does (checks for session, considering all edge cases, offline, online)
  • should we return the subscriptions, or not? (you don't need them, but could it actually be useful to return {ok, Subs}?
  • are there any existing alternatives to getting session info?

@rbino
Copy link
Author

rbino commented May 5, 2020

Hi @ioolkos!
I will describe you our usecase to avoid the xy problem: a user tries to push data towards a device using qos > 0 (using direct_plugin_export).

If the device has a session and it's currently offline, it will get the data when it reconnects, but if the device doesn't have any session, I want the call to fail informing the user that the delivery can't be guaranteed (in the future we could have an internal mechanism to handle this case).

So what I'm interested in is "If I publish with qos > 0, will the device get this"?

I'm not 100% sure what I've done here is enough or it should be something more like what happens here https://github.com/vernemq/vernemq/blob/master/apps/vmq_server/src/vmq_reg.erl#L186

I've tested locally and for a simple case it works (returns false before the device connection, true after device connection and true again when the device disconnects) but let me know if I'm forgetting some edge case (still wrapping my head around VMQ internals).

@rbino
Copy link
Author

rbino commented May 5, 2020

...and, as usual (rubberduck 🦆), by describing the problem I've probably found the solution: PublishFun returns {ok, {LocalMatches, RemoteMatches}}, so instead of checking if a session exists before publishing, I should check that either LocalMatches or RemoteMatches is 1, otherwise no one is going to receive the message.

Does it make sense @ioolkos? If that returns 1 do I have the guarantee that the message will be delivered when the device comes back online?

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.

2 participants