[rabbitmq-discuss] publisher confirmations

Marek Majkowski majek04 at gmail.com
Mon Nov 28 11:01:33 GMT 2011


Hi,

I'm not sure if it works - but the pika example showing
publisher confirms usage looks rather similar:

https://github.com/pika/pika/blob/120fdea5913e7ed80536ff55634ab0f8f4554e79/examples/demo_send_confirmed.py

Cheer,
  Marek

On Sun, Nov 27, 2011 at 15:20, bergundy <roey.berman at gmail.com> wrote:
> Hi everyone,
>
> I couldn't find code for implementing publisher confirmations.
>
> I wrote this piece of code using pika 0.9.5 (python client).
> Would like to get feedback on this, I hope I got it right ...
>
> ---
> class ConfirmingProducer(object):
>    def __init__(self, channel):
>        self.delivery_tag = 1
>        self.acked        = 0
>        self._callbacks   = {}
>        self.chan = channel
>        self.chan.confirm_delivery(self.on_delivered)
>
>    def publish(self, message, callback, **kwargs):
>        self._callbacks[self.delivery_tag] = callback
>        self.delivery_tag += 1
>        self.chan.basic_publish(message, **kwargs)
>
>    def on_delivered(self, frame):
>        success = isinstance(frame.method, pika.spec.Basic.Ack)
>
>        if frame.method.multiple:
>            for dtag in range(self.acked+1, frame.method.delivery_tag
> +1):
>                self._callbacks.pop(dtag)(success)
>            self.acked = frame.method.delivery_tag
>        else:
>            self._callbacks.pop(frame.method.delivery_tag)(success)
>            self.acked += 1
> _______________________________________________
> rabbitmq-discuss mailing list
> rabbitmq-discuss at lists.rabbitmq.com
> https://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss
>


More information about the rabbitmq-discuss mailing list