hivemq/hivemq-mqtt-client

What is use of acknowledge function in Mqtt5Publish class ?

Shalaka1197 opened this issue · 2 comments

What is use of acknowledge function in Mqtt5Publish class ?
void acknowledge();

Please let me know if there is any example for this.

Hi @Shalaka1197 - that function allows for the manual acknowledgement of received publish messages. Valid for QoS levels 1 and 2, there are certain scenarios where you may have multiple clients receiving messages and only want to acknowledge the message when the client takes ownership of the message.

From the front page README:

Screenshot 2024-03-05 at 13 11 54

An code example would be along the lines of the following:

final Mqtt5SubAck subAck = client.subscribeWith()
                .topicFilter("demo/topic/a")
                .manualAcknowledgement(true)
                .callback(publish -> {
                    boolean success = false;

                    // Some logic & conditions

                    if (success) {
                        publish.acknowledge();
                    }
                })
                .send().join();

I filed issue #621. We should add documentation on this.

Does the above information answer your question?

Documentation on manual acknowledgement has been added here as well now.

I'll close out this issue but if anything remains, let us know!