1

I'm working on HiveMQ Websocket Client and I'm facing some issues with the message delivery. so, I've come across the word PUBACK

let me explain you about my understanding and then I will ask my question.

whenever we send a message with QOS1, the hivemq server will acknowledge the sender with a PUBACK callback.

Now, I'm planning to subscibe to onPubackReceived event in my websockets, but the event is not firing after sending the message.

My Code:

var clientId = ClientIdentifier;


    mqtt = new Messaging.Client(
                    host,
                    port,
                    clientId);
    var options = {
        timeout: 3,
        keepAliveInterval: 60,
        useSSL: useTLS,
        cleanSession: cleansession,
        onSuccess: onConnect,
        onFailure: function (message) {
            connected = false;            
            setTimeout(MQTTconnect, reconnectTimeout);
        }
    };

    mqtt.onConnectionLost = onConnectionLost;
    mqtt.onMessageArrived = onMessageArrived;
    mqtt.onPubackReceived = OnPubackReceived;

Both the onConnectionLost and onMessageArrived are firing properly when a connection lost and message arrived, but the onPubackReceived is not firing.

please let me know, if I have understood it correctly or if I'm doing some mistake?

RealSteel
  • 1,871
  • 3
  • 37
  • 74

1 Answers1

4

This not a HiveMQ issue.

My assumption is, that you used the HiveMQ Websocket Client as a starting point for your implementation.

In any case a Paho MQTT Client does not have a onPubackReceived field. If you provide more details about your use case or what's your issue with message delivery, I might be able to point you into the right direction.

EDIT: What you are describing is called Quality of Service 1 in MQTT. It is a guarantee, that a message is received at least once. It is the client implementation's job to keep this guarantees and therefor resend a message, should a PUBACK not be received. Manually interfering with this behaviour in your application would result in inconsistency regarding the client's persistence. For clarification: Simply setting duplicate=truewill not result in a message being recognised as a duplicate. It will also have to have the the same messageID as the original. I was not able to actually find any documentation about paho.jskeeping the Quality of Service = 1. However, MQTT.js does.

QoS 1 : received at least once : The packet is sent and stored as long as the client has not received a confirmation from the server. MQTT ensures that it will be received, but there can be duplicates.

To sum things up:

  • Resending of messages, no PUBACK was received on, is the client Object's job. This is part of the MQTT specification.
  • Using the MQTT.js works over Websockets and ensures to keep QoS levels

Hope this helps.

fraschbi
  • 533
  • 3
  • 6
  • In my case, when ever we get connected to mqtt we push a message and make the `status` of that message as `sent` but some of the times, it is `not even reaching tcp of MQTT Server`. So, we thought of implementing `PUBACK` and if we don't receive the puback, we will `resend` that message again with `dup flag`. – RealSteel Mar 23 '17 at 05:06
  • Can you suggest me some other library where I can receive the PUBACK response on web sockets? – RealSteel Mar 23 '17 at 05:08