Dave Sag
Dave Sag

Reputation: 13486

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

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

User Manager

User Collector

There are also other services that listen for events like

In addition there are services that listen for more general events like

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

Upvotes: 1

Views: 1713

Answers (1)

Giri Chintala
Giri Chintala

Reputation: 130

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

Upvotes: 1

Related Questions