best practice
I am trying to synchronize three microservices I have.
In order to do so I've implemented RabbitMQ. It seems as if things currently work but I am not sure if I'm following best practice and I couldn't find a reference to look it up, maybe someone could help me with that?
Brief of what I am trying to do: I have one service who should update the two others, each of the services should receive the message sent. I have two types of messages (save and delete resource). * In case of fault the queue should recover and resend the messages.
What I am currently doing: I've set up an exchange and each of my consumers connect to two different queues, one for each type of message (save/delete). I've used a direct exchange in order to filter the messages later on, even though currently I don't need to filter them.
Each of the queues are named, and the exchange as well as the messages are durable and I'am acking the messages I've consumed.
The question Should I set a different queue for each type of event or should I send the messages on the same queue and filter them? Is the use of RabbitMQ described above is the correct solution for the problem. What is the best practice?
Your setup is correct.
One common rule when designing queues in rabbit is, one queue for one type (type here means different handling logic) of consumers. So, since you have two types of consumers. They have different logic for different types of events (save/delete), one queue for each is exactly correct.
If you want to have only one type of consumer, which could handle both save and delete events, then to use one queue is also OK.
But two types of consumers and one shared queue will not work. Coz when multiple consumers subscribing to one queue, events are dispatched to consumers in kind of round-robin way, so either of your consumers could only receive half of the events.
链接地址: http://www.djcxy.com/p/34218.html上一篇: asp.net web api
下一篇: 最佳实践