RabbitMQ — Why are my Routing Keys being ignored when using topic exchange

笑着哭i 提交于 2019-12-11 11:13:29

问题


I'm using RabbitMQ to coordinate events between a collection of services as follows:

User Manager

  • emits user.collect when it wants user data to be collected from a separate service
  • listens for user.collected which is emitted by a separate service

User Collector

  • listens for user.collect when it is supposed to collect some user data, and
  • emits user.collected when 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

  • #.created
  • user.#

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.

  1. Queue delivery message to one of it's consumer, not to all of it's consumers.
  2. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!