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

Document How to listen for Message acknowledgements from broker on successful delivery to the broker. #203

Closed
akshg05 opened this issue Jul 12, 2020 · 7 comments

Comments

@akshg05
Copy link

akshg05 commented Jul 12, 2020

I was unable to find how to listen to updates where the broker acknowledgements for the client messages are receiver. I can see them in the logs. Is there an existing way to accomplish this?
I was trying to do something like this below :

client.published.listen((event) { 

      print('Message published');
    });

The above code didn't work and the listener was never fired.
Could you please guide here or point to specific documentation?

@akshg05
Copy link
Author

akshg05 commented Jul 12, 2020

I tried one of the examples you provided and noticed that the published stream receives completion notification for messages only for subscriptions to which the publisher has subscribed.
For instance,
If Publisher A publishes to topics Topic1, Topic2 and subscribes to Topic 2 only, it would only receive completion notification for Topic2 and not for Topic1 on the published stream.

We would want to have acknowledgement receipts from the broker that the Message has been received on their end on all topics including to which publisher has not subscribed to.
Currently the logger does log the ACK from broker with identified id I believe. However, could find no means to get it on a stream.

@shamblett
Copy link
Owner

I'm not sure what you mean when you say 'publisher', presumably you mean the client? The client only tracks topics you have subscribed to. Protocol support messages(PUBAK, PUBREL PUBCOMP etc.) are not exposed outside of the client, it handles this for you.

When you say

We would want to have acknowledgement receipts from the broker that the Message has been received on their end on all topics including to which publisher has not subscribed to.

What do you mean by 'the message' and 'publisher'? Could you please rephrase this to be more specific as to what you want the client to do. e.g 'I call this method on the client, I would then expect.......then....'.

@akshg05
Copy link
Author

akshg05 commented Jul 12, 2020

Yes, by publisher I mean the client who is at the moment publishing a message.
By message I mean the message the client published to a topic
I'll try explain it a bit more elaborately :
If I publish a message messageA being a publisher. I need an acknowledge receipt from the broker that it received my messageA which the app can process so that I can be sure my message has been delivered to the broker.

So what I expect is a stream to which I can listen to for Ack Messages from the broker.
I believed the below stream did it :

client.published.listen((event) { 

      print('Message published');
    });

But it doesn't :(
Although not clearly documented, I am wondering if we could reuse the subscription manager of the client although it's protected to accomplish this.

@shamblett
Copy link
Owner

Ok, the API doc for the published stream states -

/// Published message stream. A publish message is added to this
  /// stream on completion of the message publishing protocol for a Qos level.
  /// Attach listeners only after connect has been called.

So, you get publish messages that have completed the MQTT protocol handshake, the client performs the handshake for you, if the message does not appear on this stream it has failed publication. You can't just listen to ack messages, for higher qos levels you will have pubrel/pubcomp messages to handle also..

So, if you publish a message and it appears on this stream the handshake is complete, if it doesn't appear it has failed handshake and so has not been published. If any of this is unclear please point it out and I'll correct it.

If this is not happening for you then I'll need a log to see exactly what is going on.

@akshg05
Copy link
Author

akshg05 commented Jul 16, 2020

The messages published by the client appear on the subscriber's end(subscribing client) which implies a successful publication, right? However, the messages still do not appear on the published stream. However, they do appear if the client publishing to the topic has subscribed to it as well.
Why is it so?
I'm saying again that messages are not appearing on the published stream despite succesful publication if the topic is itself not subscribed to.
You can try the same with one of your examples listed in examples dir as I did by removing a subscription to JHTopic1 but continue publishing on that topic. Broker Ack messages are received but messages pertaining to JHTopic1 don't appear on published stream.
I hope I'm clear now.

@shamblett
Copy link
Owner

Yes got you, when I changed the example as you suggested topic1 wasn't added to the publish stream when the publish ack was received. As far as I can see this only affects QOS 1. I'll update the package and re-release it shortly.

@shamblett
Copy link
Owner

Package re published at version 7.3.0, please test again and see if the behavior is what you are expecting.

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

No branches or pull requests

2 participants