[rabbitmq-discuss] Using Pika Python client library with BlockingConnections and publisher-confirms - Does it work?
ask at rabbitmq.com
Mon Feb 6 13:34:05 GMT 2012
On 6 Feb 2012, at 13:13, Marek Majkowski wrote:
> 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()
>>> promise = client.basic_publish(exchange='', routing_key='test',
>>> body="Hello world!")
>>> </shameless plug>
>> But that doesn't use publisher confirms?
> Internally it does. `client.wait` will block until pub-ack or an
> error comes back.
Right, in pika/kombu you would use drain_events(), but that doesn't change
the points I presented. Though, kombu/pika donsn't have a simple solution to wait
for a specific event like pika does (afaik).
If I had to do it synchronously, I would not do it on an event by event basis,
but instead limit the active number of publishes, something like:
active = 0
limit = 10
timeout = 180
def __init__(self, channel, limit=None, timeout=None):
self.channel = channel
self.limit = limit if limit is not None else self.limit
self.timeout = timeout or self.timeout
self.active -= 1
def publish(self, body, **options):
self.active += 1
while self.active >= self.limit:
More information about the rabbitmq-discuss