gdaws/stompit

client.ack() doesn't seem to impact message delivery

Opened this issue · 2 comments

Looking at the documentation for the Client:

client.subscribe(headers, onMessageCallback)
Create a new subscription. A SUBSCRIBE frame is sent with the headers set in the headers argument. The onMessageCallback function is called each time a new message is received. Every message must be read and acknowledged, even if you don't consume the message in your application (in this case you would send a negative acknowledgment). You must not ignore a message, doing so would block other communications with the client. If you are unable to read a message then you must terminate the connection using the client.destroy method.

In implementation it seems that while not reading a message will delay delivery of new messages, client acks/nacks do not. If the the message is read, it seems that a client.ack(message) or client.nack(message) does not change whether new messages are received by the client.

Is this the expected behavior?

By default, messages are automatically acknowledged when you read them.
You can use ack: 'client-individual' in the subscribe options if you want to manually ack

I confirm that using this headers:

// subscribe to queue
        client.subscribe({
            'destination': '/queue/test1',
            // ack mode
            // ack:client-individual: manually send ack / nack
            // ack:client-auto: do not send ack / nack
            // ack:client:
            'ack': 'client-individual'
        }, function (error, message) {

it works as expected when then validating the message and sending

// validate this message
                if(isMessageOk) {
                    client.ack(message);
                } else {
                    client.nack(message);
                }