Closed ibraimgm closed 3 years ago
Depends what you want to do. A queue group allows to distribute the same message to 1 of the member of the group as opposed to all subscribers to a given subject. What you are doing here is create 3 different groups since the subject is different, so this application would receive messages on all 3 subjects. If there is another instance of the same application running, then a message on "subject1" would go to only one instance of the applications. If this is what you want, then yes, your use of queue subscription is correct. If you want all instances running the above code to receive a given message on a given subject, then you should not use QueueSubscribe, but just Subscribe.
You can (and should) call sub.Close() when your application is done receiving. This will not remove the durable interest in the server. To do so, you would need to call sub.Unsubscribe().
Here is more information on various type of subscriptions in NATS Streaming: https://docs.nats.io/nats-streaming-concepts/channels/subscriptions
Thanks for the quick reply @kozlovic , now I understand it.
I need to subscribe to 3 different subjects in the same application, all of the subscriptions should be durable.
Is it enough to just call
QueueSubscriber
with the same group (multiple replicas of the application) and same durable name? For example (note that only the subject and the handler changes):Is this correct? Or should the queue+durablename be unique for each subject?
Also, assuming I don't want to miss any messages, will I ever need to close those subscriptions? for what I understood, once the subscription is closed, everything is lost...