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

Question: how to get notified of puback for QoS1 on the client #944

Open
srinivasrb opened this issue Jun 19, 2020 · 9 comments
Open

Question: how to get notified of puback for QoS1 on the client #944

srinivasrb opened this issue Jun 19, 2020 · 9 comments
Labels
question It is a question regarding the project

Comments

@srinivasrb
Copy link

When using QoS1 on the client, what is the callback that is invoked for the PUBACK from the server?

  • I understood that ApplicationMessageReceivedHandler is used for receiving messages on topics that the client subscribed to? If this is also used for PUBACK, how do I distinguish between these and subscription-related messages?
  • What is the ApplicationMessageProcessedHandler used for?

Which project is your question related to?

  • Client
  • ManagedClient

Thanks in advance!

@srinivasrb srinivasrb added the question It is a question regarding the project label Jun 19, 2020
@SeppPenner
Copy link
Collaborator

I guess, you cannot get plain PUBACK messages at all... This is handled internally as far as I know. @chkr1011 This is something you need to answer.

@srinivasrb
Copy link
Author

srinivasrb commented Jun 19, 2020

Thanks, @SeppPenner. My context is I have a client app that sends a set of messages, and then reports that it was able to send them successfully. In QoS 0, success would be if I was able to send, but for QoS 1, I'd consider that success is if it is successfully received, as determined by a PUBACK. Is there an alternative manner in which I can know that the message was indeed received?

@kedar-hatkar
Copy link

Thanks, @SeppPenner. My context is I have a client app that sends a set of messages, and then reports that it was able to send them successfully. In QoS 0, success would be if I was able to send, but for QoS 1, I'd consider that success is if it is successfully received, as determined by a PUBACK. Is there an alternative manner in which I can know that the message was indeed received?

@srinivasrb

I am using EMQX mqtt broker, In case of EMQX broker, if there is 0 subscriber for a topic then broker drop that particular message which client A has published. In this scenario, Client A may not come to know whether message is received by subscribers or not.

You can check if below solution can solve your problem.

Client can wait for message delivery confirmation from subscriber in terms of acknowledgement.

Client A will publish a message with unique message identifier in payload. When subscriber receives such message, subscriber can publish a simple message along with that identifier on a acknowldgement topic. Client A will subscribe to this topic and can recieve messages.

Then client A can updated flags in its system as messaged delivered.

@SeppPenner
Copy link
Collaborator

@kedar-hatkar That was the idea I would have suggested as well as I don't think this is possible natively.

@srinivasrb
Copy link
Author

Thanks, folks. In my case, I don't have control over the subscriber so I won't be able to get the subscriber to send an ack message explicitly. I am only interested in knowing whether the send to the broker succeeded - and I understand that QoS 1 is basically that - when the broker has received the message, it sends a PUBACK, so the client is assured of the 'at least once' success.

Earlier, I was using M2MQTTClient, and that did give me a PUBACK. Any way I can get that to happen for MQTTNet?

@liaoliaoda
Copy link

hi, have you solve that problem, I have the same problem now.

@liaoliaoda
Copy link

Paho.Java have the callback function when msg published success or fail. but not mqttnet. M2mqtt also have callback when meg published success.

@SeppPenner
Copy link
Collaborator

Messages are considered as published when the awaited Task returns and doesn't run into an exception.

try
{
    var message = new MqttApplicationMessageBuilder()
        .WithTopic("MyTopic")
        .WithPayload("Hello World")
        .WithExactlyOnceQoS()
        .WithRetainFlag()
        .Build();

    await mqttClient.PublishAsync(message, CancellationToken.None);
    // If we reach this line, the publish worked.
}
catch (MqttCommunicationException ex)
{
    // I'm not sure about the exact name of this exception class...
    // There was an error, message maybe wasn't sent (Depending on the exception type / message).
}

@liaoliaoda
Copy link

Hi, we can realize this function in MQTTnet.Extensions.ManagedClient.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question It is a question regarding the project
Projects
None yet
Development

No branches or pull requests

4 participants