hivemq / hivemq-mqtt-client

HiveMQ MQTT Client is an MQTT 5.0 and MQTT 3.1.1 compatible and feature-rich high-performance Java client library with different API flavours and backpressure support
https://hivemq.github.io/hivemq-mqtt-client/
Apache License 2.0
824 stars 153 forks source link

What is use of acknowledge function in Mqtt5Publish class ? #614

Closed Shalaka1197 closed 3 months ago

Shalaka1197 commented 5 months ago

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

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

pglombardo commented 4 months ago

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?

pglombardo commented 3 months ago

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

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