Is there any example or design of a queue system in microservices?

28 views Asked by At

I just start to learn about microservices and message queue (rabbitmq) and I understand some exchanges as Direct, Topic,Fanout,Header,etc. But I do not clear about something like when should we close the connections? How many queue and exchange we should have? Many thanks (ps: I am using express for running services)

I already create connections, exchanges, queues and send and receive messages successful. I expect to know the design or knowledge to build the whole system

1

There are 1 answers

0
idanz On

I recommend you to go over RabbitMQ documentation, specifically the API guide (here is the Java guide for example).

  1. Regarding closing connection/channel - see Connection and Channel Lifespan:

Client connections are meant to be long-lived. The underlying protocol is designed and optimized for long running connections. That means that opening a new connection per operation, e.g. a message published, is unnecessary and strongly discouraged as it will introduce a lot of network roundtrips and overhead.

Channels are also meant to be long-lived but since many recoverable protocol errors will result in channel closure, channel lifespan could be shorter than that of its connection. Closing and opening new channels per operation is usually unnecessary but can be appropriate. When in doubt, consider reusing channels first.

  1. Regarding how many queue and exchanges you should use - the answer is it depends. This is 100% dependent on your business case and the architecture. Some would choose to separate queue by the message model, and others won't care to have in the same queue different models. Some would define queues topology to optimize performance, and other won't care about performance. There is no a recipe for that.