Reputation: 233
I'm new to NATS and have read all the examples for: https://nats.io/documentation/concepts/nats-messaging/
I'm in Microservciearchitecture where in microservice-Y (MSY) need to store some information published from other microservice-X (MSX) I have 2-10 instances of MSY so when changes are made in MSX and MSX-instance publishes event I want that only 1 instance of MSY should save information so not all of them save the same data. I have read Request-Repy: https://nats.io/documentation/concepts/nats-req-rep/ but there seems that all of instances receives message (and will handle it) even if it is point-to-point and reply is handled just for the one instance that is quickest to reply
Is this correct or have I missunderstood example? If I only need that 1 instance of MSY should handle given message (store data in db) what can I do to acheve this?
Upvotes: 4
Views: 1505
Reputation: 862
Use queue groups. If you have multiple subscriptions on the same subject with the same queue group, only one of the members of the group will receive the message. Check this out: https://nats.io/documentation/concepts/nats-queueing/
Upvotes: 2