Queueing Walkthrough
Last updated
Was this helpful?
Last updated
Was this helpful?
NATS supports a form of load balancing using . Subscribers register a queue group name. A single subscriber in the group is randomly selected to receive the message.
If you have not already done so, you need to the nats
CLI Tool and optionally the nats-server on your machine.
The nats reply
instances don't just subscribe to the subject but also automatically join a queue group ("NATS-RPLY-22"
by default)
In a new window
In a new window
You should see that only one of the my-queue group subscribers receives the message and replies it, and you can also see which one of the available queue-group subscribers processed the request from the reply message received (i.e. service instance A, B or C)
You should see that a different queue group subscriber receives the message this time, chosen at random among the 3 queue group members.
You can also send any number of requests back-to-back. From the received messages, you'll see the distribution of those requests amongst the members of the queue-group. For example: nats request foo --count 10 "Request {{Count}}"
You can at any time start yet another service instance, or kill one and see how the queue-group automatically takes care of adding/removing those instances from the group.
Queue groups using the NATS CLI