basis-company / nats.php

nats jetstream client for php
116 stars 29 forks source link

fix ack payload rendering #89

Closed chazzbg closed 2 weeks ago

chazzbg commented 2 weeks ago

Currently the payload generated to publish a NAK is wrong and does not result of actually nak-ing a message.

According to the documentation, acknowledgment is done only by sending the reply string, but Ack prorotype here generates adds +ACK command in the payload it results in a mesasge like this PUB $JS.ACK.sample-stream.psub.3.1.21.1719946162089866350.0 +ACK 0 but the actual that is required is this PUB $JS.ACK.sample-stream.psub.3.1.21.1719946162089866350.0 0

When generating NAKs, the problem continues. It generates a message like this PUB $JS.ACK.sample-stream.psub.3.1.21.1719946162089866350.0 -NAK 21\r\n{"delay": 5000000000} but the expexted nack string is PUB $JS.ACK.sample-stream.psub.2.1.11.1719946162089866350.0 26\r\n-NAK {"delay": 5000000000}

The -NAK command is required to be part of the body and included in the lenght of the message, not before the length. Here are some samples from the Python library that i've traced

b'PUB $JS.ACK.sample-stream.psub.3.1.21.1719946162089866350.0  0\r\n\r\n'
b'PUB $JS.ACK.sample-stream.psub.1.1.1.1719946162089866350.9  4\r\n-NAK\r\n'
b'PUB $JS.ACK.sample-stream.psub.2.1.11.1719946162089866350.0  26\r\n-NAK {"delay": 5000000000}\r\n'
b'PUB $JS.ACK.sample-stream.psub.4.1.31.1719946162089866350.0  4\r\n+WPI\r\n'

With the issue above, when you try to nak a mesage with delay, message is always delayed only 30s which is not the actual delay but the default AckWait for the consumer.

With the current PR the issue should be fixed

nekufa commented 2 weeks ago

thanks @chazzbg