RabbitMQ is very flexible, you could have many different exchange and queue design solutions to meet your requirement.
But, first, we need to understand the relationship and basic rule between queues and consumers:
- If you want a message type to be consumed by only one of all consumers, as you said, you need a worker queue, all the consumers should subscribe to it.
- If you want to a message type to be consumed by each of the consumers, you need to have queues for each consumer, and each consumer only subscribe to its own queue.
When number of queues are clear based on the above understanding. Things left is how to route your messages to these queues. There will be many solutions. Below are just some examples.
One workable solution is to create two exchanges, one for each message type.
| message type | exchange name | exchange type | bound queues |
|------------------------------------------------------------------|
| type_1 | exchange1 | fanout | shared_queue |
| type_2 | exchange2 | fanout | queue1,queue2,... |
Another workable solution is, if you want to have only one exchange for publishing the two message types to, use 'direct' exchange type:
| routing_key | binding_key | bound queues |
|-----------------------------------------------|
| type_1 | type_1 | shared_queue |
| type_2 | type_2 | queue1,queue2,... |
One exchange could have multiple queues bound to it with same binding key. So, when publishing message type 1 with a publish routing key - "type_1", only the shared_queue will receive the message; when publishing message type 2 with publish routing key - "type_2", all the queue1,queue2,... will receive the message.
Use different binding keys for each messages might not be ideal for real cases in case you have more message types and you don't want to use the same routing keys. If so, you might want to use "topic" exchange type instead:
| routing_key | binding_key | bound queues |
|-----------------------------------------------|
| type_1.1 | type_1.* | shared_queue |
| type_2.2 | type_2.* | queue1,queue2,... |