Using pub / sub will cause messages to be processed twice (account) or trice (logistics), if I understand correctly.
you probably have 1 queue per employee, based on your description, and you send a message to all work queues. therefore, each worker receives a copy of the message because you sent the message to all the queues.
what you need is one queue of "accounts" and one "logistic" queue. You will have several accounts in one queue; the same for the logistic service / queue.
setting prefetch = 1 is also important. this prevents you from immediately reading too many messages to one employee.
Is there a way to combine both and have work queues for each of the services without sending 2 separate events / messages to two different exchanges?
yes - do not use split exchanges. use a topic or direct exchange and use several routing keys to route a single message both in the account queue and in logistics.
What would be the right way to ensure that the “account” and “logistics” process the message only once?
there is no way to guarantee this, 100%. at some point, even with the correct configuration, as I described, you will have a network failure or a worker crash or some other problem, and the message will be processed twice. you should consider this in your design using idempotence in the processing form .
hope this helps!
Derick bailey
source share