kombu
kombu copied to clipboard
Maybe incorrect description about kombu.Queue in the documentation
According to this, a queue with a direct exchange matches if the routing key property of the message and the routing_key attribute are identical. But I'm not sure if this description holds true.
Here is an counter example.
# queues.py
import kombu
my_queue = kombu.Queue('my_request', exchange=None, routing_key='ignored')
# consumer.py
from kombu.mixins import ConsumerMixin
from queues import my_queue
class Worker(ConsumerMixin):
def __init__(self, connection):
self.connection = connection
def get_consumers(self, Consumer, channel):
return [Consumer(queues=[my_queue],
callbacks=[self.process_task])]
def process_task(self, body, message):
print(body)
message.ack()
if __name__ == '__main__':
from kombu import Connection
with Connection("amqp://guest:guest@localhost:5672//") as conn:
worker = Worker(conn)
worker.run()
# producer.py
from kombu.pools import producers
if __name__ == '__main__':
from kombu import Connection
connection = Connection("amqp://guest:guest@localhost:5672//")
with producers[connection].acquire(block=True) as producer:
producer.publish("Hello world", # Use direct exchange
routing_key='my_queue')
As you can see, you can simply set routing_key to whatever string you like. I think the document should state that routing_key attribute for a queue is ignored when direct exchange is used.