[rabbitmq-discuss] Using Pika Python client library with BlockingConnections and publisher-confirms - Does it work?

Marek Majkowski majek04 at gmail.com
Mon Feb 6 13:13:35 GMT 2012


On Mon, Feb 6, 2012 at 12:40, Ask Solem <ask at rabbitmq.com> wrote:
> On 6 Feb 2012, at 11:59, Marek Majkowski wrote:
>
>> <shameless plug>
>> It's rather simple using Puka:
>>
>>   client = puka.Client("amqp://localhost/")
>>
>>   promise = client.connect()
>>   client.wait(promise)
>>
>>   promise = client.basic_publish(exchange='', routing_key='test',
>> body="Hello world!")
>>   client.wait(promise)
>>
>> https://github.com/majek/puka/blob/master/examples/send.py
>> </shameless plug>
>
>
> But that doesn't use publisher confirms?

Internally it does. `client.wait` will block until pub-ack or an
error comes back.

> It may take a long time for a confirmation to arrive, so blocking while
> waiting for a publisher confirm is likely to be very inefficient.  But if that
> is sufferable then this would also be possible using kombu/pika.

You can do other things in the meantime, for example create queue
or publish another message, just need to synchronize at some point
(we're talking about  sync programming style here).

    promise1 = client.basic_publish(exchange='', routing_key='test',
body="Hello world!")

    promise2 = client.queue_declare(queue='test')
    client.wait(promise2)

    promise3 = client.basic_publish(exchange='', routing_key='test2',
body="Hello world!")
    client.wait(promise3)

    client.wait(promise1)

Of course you may wait for any of the three promises and so on.

(Alternatively you can use callbacks and async programming if
you want to know about the pub-ack when-it-happens, but
that's another story)

Marek


More information about the rabbitmq-discuss mailing list