Search code examples
rabbitmqamqppika

How to use routing_key and queues


I'm setting up a consumer that will listen for messages from two different sources. I want to have a different callback for messages from these two sources(other solutions are welcome though).

I'm very new to rabbitmq and pika and I haven't grasped the nitty gritty details yet. But what i want to know is:

Should i use different queues and setup two

channel.basic_consume(callback_1, ...)
channel.basic_consume(callback_2, ...)

for my callbacks or should i do some tricks with routing keys instead?


Solution

  • That depends on your needs a little. It's really about processing, I am most familiar with Java so I will tell you how I handle things and then you can make a decision based on that.

    If I need to have different threads process different data or do different things with the data I create two different queues and each thread will consume a different queue. I use topic exchanges to make sure the queues get the correct messages. If the data is only slightly different then using the routing key I can handle the data differently with the same thread. The decision is purely based on the parallelism I require, ie how many queues I want processing the data.