setStartWithLastReceived double delivers last acknowledged message
See original GitHub issueHi, I am setting up a subscription with queue groups and durable name, and I am using the setStartWithLastReceived
option. Receiving messages works just fine, but when I restart my consumer, I get the last message I had already received in the previous session. I know thats what setStartWithLastReceived
sounds like, but I had thought/hoped that we would start off with any new un-acked messages, rather than last one I had already processed. So, essentially, I have double delivery of the last message during consumer restarts. Is this expected? Should I be using some other option?
Here is the code snippet:
const opts = this.client.subscriptionOptions().setStartWithLastReceived().setDurableName("durable-name");
const subscription = this.client.subscribe(topic, queue, opts);
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
node-nats-streaming/README.md - UNPKG
NATS Streaming offers At-Least-Once delivery semantics, meaning that once a message has been delivered to an eligible subscriber, if an acknowledgement is not ......
Read more >JavaScript nuid next Examples
it('subscribe after 500ms on last received', (done) => { const stan ... getData()).equal('first', 'second message was not the one expected'); stan.close(); ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
OK, I don’t see this problem with this code:
stan-pub.js:
stan-sub.js:
On next restart of subscriber:
Looks like there is a bug in the moleculer stan transporter code.
There are quite a few concepts that you should read about here:
https://docs.nats.io/developing-with-nats-streaming/receiving
In a nutshell:
For regular subscriptions, the server only maintains state until the client closes, or unsubscribes - this allows the server to remember to resume a channel when it crashes and is using a persistent store. From the client’s perspective, close and unsusbscribe are equivalent.
When you have a durable subscription the server remembers the messages you have not acknowledged and resends them to you until you unsubscribe. If your client closes(), it still remembers your position in the stream. It is possible that the server may send you a message again. You can check this with
isRedelivered()
, as the server only knows you got the message if it receives an acknowledgment from the client.When you
unsubscribe()
, the server stops sending you messages from that channel, and drop the state you had on the channel.Queue subscriptions are similar to a non-queue durable with the exception that
unsubscribe()
only drops the channel’s state for the queue when all clients unsubscribe. This allows the queue to grow or shrink while still maintaining state on the channel.