How the publishing client gets acknowledgement that the message is sent to the broker

I have a scenario where an mqtt-client (java application) publishes message to the mqtt-broker using the below code.

.whenComplete((connAck, throwable) → {“Debug: connAck=” + connAck);

  1. Is this “whenComplete()” invoked when the message has reached the mqtt-broker? or just after publish method is invoked by the publisher-client? or broker has send the message to the subscriber-client? or after subscriber has received the message?

  2. Can I consider this whenComplete() as an acknowledgement?

  3. In case of successful ack → throwable is null
    In case of failure ack → throwable is not null

In either case (success/failure ack), the publishing-client has to perform certain operation (application-level operation) on the message?
a. In successful ack - how to uniquely identify acknowledgement corresponding to a message? (Suppose, the publisher-client has published 100 msgs, how the publisher-client will uniquely identify for which message the acknowledge has been received?)
b. In failure ack - the publishing-client is not getting the message, it is just getting a throwable object.

Hi @Abhishek ,

Please take a look at the example: hivemq-mqtt-client/ at master · hivemq/hivemq-mqtt-client · GitHub – where an async client connects to the broker, publishes a message, receives the result and disconnects.

I hope it helps,
Dasha from HiveMQ team