问题
I'm using RabbitMQ to coordinate events between a collection of services as follows:
User Manager
- emits
user.collectwhen it wants user data to be collected from a separate service - listens for
user.collectedwhich is emitted by a separate service
User Collector
- listens for
user.collectwhen it is supposed to collect some user data, and - emits
user.collectedwhen it's collected the data.
There are also other services that listen for events like
user.created,user.updated,user.deleted
In addition there are services that listen for more general events like
#.createduser.#
and so on.
So I am using a topic exchange.
My setup is as follows
| exchange | type | queue | routingKey |
| -------- | ----- | --------------- | -------------- |
| MY_APP | topic | USER_COLLECTION | user.collect |
| MY_APP | topic | USER_COLLECTION | user.collected |
All of the services talk to the exchange called MY_APP.
The User Manager creates a producer that emits the user.collect event to the MY_APP exchange with routingKey user.collect, and it creates a consumer that listens on the queue USER_COLLECTION for events with routingKey user.collected.
The User Collector creates a producer that emits the user.collected event to the MY_APP exchange with routingKey user.collected and it creates a consumer that listens on the queue USER_COLLECTION for events with routingKey user.collect.
However I'm finding that the User Manager emits user.collect and this is picked up by the User Manager itself with the listener for user.collected.
It's as if the routingKey is being ignored. What am I doing wrong?
Update
See follow up question
回答1:
Create different queues for each Consumer and bind queue(s) to topic exchange using appropriate binding key user.collect or user.collected.
- Queue delivery message to one of it's consumer, not to all of it's consumers.
- Messages are routed to Queue(s) based on it's binding key to Topc Exchanges.
Check this link for more detailed examples. https://www.rabbitmq.com/tutorials/tutorial-five-python.html
来源:https://stackoverflow.com/questions/52928669/rabbitmq-why-are-my-routing-keys-being-ignored-when-using-topic-exchange