nats-io / stan.net

The official NATS .NET C# Streaming Client
Apache License 2.0
137 stars 41 forks source link

Consumer does not process message without Deliver options #173

Closed minhhungit closed 4 years ago

minhhungit commented 4 years ago

follow issue https://github.com/nats-io/stan.net/issues/171

Currently I see it works well with this command:

.\StanSub -qgroup newgroup -clientid xyz -all

But when I remove -all/-seq/-last then it won't process message It also does not process message when I add durable param like this

.\StanSub -qgroup groupA -clientid xyz -all -durable aaaa

In another hand, when I used param -last it just show the last message in streams, I thought it will process message from the last message that it processed before at the point consumer is stopped

And sometime with -durable it process the last message it stopped in the last times, but sometime it does not do anything

Added video for reproducing

issues-with-nats-client.zip

ColinSullivan1 commented 4 years ago

@minhhungit , thank you for the video.

Last is behaving as expected, --last will always return the last message the streaming server has received on the channel, not the last message your subscriber has received (I need to fix that documentation). To pick up where you've left off between test runs, you'll want to use a durable subscriber.

When you start the durable, without the --all flag, you're on registering interest in new messages from the streaming server. To get previously published messages, you'll need to set the sequence number through -seq, -since, or -all.

To reset between test runs, use the -unsubscribe true parameters and the durable will unsubscribed (clearing out the subscription).

minhhungit commented 4 years ago

Thank you for your explained @ColinSullivan1

Does server auto unsubscribe for a period of time, for example in case subscriber is crashed, if it has that feature then how long

And what is expected if we start the durable without --all flag, I see that it does not do anything, is that correct

ColinSullivan1 commented 4 years ago

@minhhungit , The server will retain state of a subscriber until it recognizes that subscriber has been disconnected. If the subscriber is durable, it'll retain that state, so the subscriber can be disconnected for any period of time and will resume where it left off until it is unsubscribed. Note that If the server has reached any of it's limits and rolled messages off, then the subscriber may not receive all of the messages sent while it was down, but this is not a common case.

If you start a durable (or any) subscription without requesting any previously published messages (in the sample, -all, -seq, -since), that subscriber will only receive messages published after the point it has subscribed.

minhhungit commented 4 years ago

Thank you @ColinSullivan1

ColinSullivan1 commented 4 years ago

Absolutely. There's documentation here that explains subscriptions in more detail.

minhhungit commented 4 years ago

Wait @ColinSullivan1 , unlucky it did not process old messages

When you start the durable, without the --all flag, you're on registering interest in new messages from the streaming server. To get previously published messages, you'll need to set the sequence number through -seq, -since, or -all

image

ColinSullivan1 commented 4 years ago

For durables, the starting position given by the client when restarting a durable subscription is ignored... The 2nd run was restarting the durable. You'll need to unsubscribe the durable with the -unsubscribe parameter to receive all messages again.

https://docs.nats.io/nats-streaming-concepts/channels/subscriptions/durable

minhhungit commented 4 years ago

I'm quite confusing with unsubscribe feature. I guess it will be really good if we have a page that show combination of options and the expectation of the combination. It will help new guys like me trace easier.

Anyway, thank you !