[rabbitmq-discuss] python publish an unroutable message

Marek Majkowski majek04 at gmail.com
Wed Jul 21 13:41:16 BST 2010


On Tue, Jul 20, 2010 at 12:42, Ovidiu Deac <ovidiudeac at gmail.com> wrote:
>> Ovidiu Deac <ovidiudeac at gmail.com> writes:
>>> Does anyone have an example of using the mandatory flag to detect
>>> unroutable messages in python?

Pika: raises an exception on basic.return
look at pika/channel.py:
    def _async_basic_return(self, method_frame, header_frame, body):
        raise NotImplementedError("Basic.Return")


Pyamqplib: looks like it appends returned message to an internal queue:
http://code.google.com/p/py-amqplib/source/browse/amqplib/client_0_8/channel.py#2426

That _basic_return code is executed only when you do ch.wait. This kind
of flow works for me:

ch.returned_messages.empty() -> True
ch.basic_publish(...)
ch.wait()
ch.returned_messages.empty() -> False

On the other hand ch.returned_messages is a standard python Queue.Queue,
so it might be safe to just block on it in a separate thread.

Cheers,
 Marek


More information about the rabbitmq-discuss mailing list