Closed dblokhin closed 2 years ago
This is because for JetStream subscriptions that the library created, Unsubscribe() will delete it. This is documented here: https://pkg.go.dev/github.com/nats-io/nats.go#Subscription.Unsubscribe and may change in the future with out JetStream API simplification project.
The issue boils down to the fact that the library auto-creates the JetStream consumer which then can lead to this unexpected (but documented) behavior. To prevent that, add a call to AddConsumer prior to starting your QueueSubscribe call and the subscription will not be removed (don't forget to specify the DeliverGroup
in the ConsumerConfig
when adding the consumer). Note that AddConsumer will be idempotent the next time you restart your application - assuming that you don't change the content of the ConsumerConfig code).
Defect
If we use an
unsubcribe()
method of subscription we have received duplication of messages despite using manualack
ornats.Durable
subscription.If we commented
unsubscribe()
for the first time of using new stream (or cleared) and then useunsubscribe()
as usual we got an expected behavior: each message is delivered at ones.Versions of
nats.go
and thenats-server
if one was involved:OS/Container environment:
docker container: nats@latests
Steps or code to reproduce the issue:
Expected result:
Actual result: