views:

193

answers:

1

I've got this strange problem using py-amqp and the Flopsy module. I have written a publisher that sends messages to a RabbitMQ server, and I wanted to be able to send it to a specified queue. On the Flopsy module that is not possible, so I tweaked it adding a parameter and a line to declare the queue on the init_ method of the Publisher object

    def __init__(self, routing_key=DEFAULT_ROUTING_KEY,
                  exchange=DEFAULT_EXCHANGE, connection=None,
                  delivery_mode=DEFAULT_DELIVERY_MODE, queue=DEFAULT_QUEUE):
        self.connection = connection or Connection()
        self.channel = self.connection.connection.channel()
        self.channel.queue_declare(queue) # ADDED TO SET UP QUEUE
        self.exchange = exchange
        self.routing_key = routing_key
        self.delivery_mode = delivery_mode

The channel object is part of the py-amqplib library

The problem I've got it's that, even if it's sending the messages to the specified queue, it's ALSO sending the messages to the default queue. AS in this system we expect to send quite a lot of messages, we don't want to stress the system making useless duplicates... I've tried to debug the code and go inside the py-amqplib library, but I'm not able figure out any error or lacking step. Also, I'm not able to find any documentation form py-amqplib outside the code.

Any ideas on why is this happening and how to correct it?

A: 

OK, I've think I've got it. unless anybody else have a better idea. I've check this tutorial on AMQP I was assuming that the publisher should know the queue, but that's not the case, you need to send the message to a exchange, and the consumer will declare that the queue is related to the exchange. That allow different options on sending and receiving, as you can see on the tutorial.

So, I've been including the exchange information on both the publisher and the consumer, not making use of the call to queue_declare and it appears to be working just fine.

Khelben