<div dir="ltr"><div>I've created a pull request which fixes the demo: <a href="https://github.com/pika/pika/pull/109">https://github.com/pika/pika/pull/109</a></div><div><br></div><div>Note:</div><div>The stable pika release (0.9.5) doesn't add the Basic.Nack and Confirm.SelectOk callbacks when you call channel.confirm_delivery()</div>
<div><div>you'll explicitly have to call channel.add_callback(on_delivered, ['Basic.Nack', 'Confirm.SelectOk'])</div></div><div><br></div><div>Would you recommend using the git master version of pika or 0.9.5 for a production environment?</div>
<br><div class="gmail_quote">On Mon, Nov 28, 2011 at 1:53 PM, Roey Berman <span dir="ltr"><<a href="mailto:roey.berman@gmail.com">roey.berman@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div dir="ltr">Thanks again for the quick response.<div><br></div><div>I also read <a href="http://www.rabbitmq.com/extensions.html#publishing" target="_blank">http://www.rabbitmq.com/extensions.html#publishing</a> before posting this question.</div>
<div><br></div><div>But again my problem is with simulating server nacks so i can create a test case for my code.</div><div><br></div><div>Do you have any idea how I can do that?</div><div><div class="h5"><div><br><div class="gmail_quote">
On Mon, Nov 28, 2011 at 1:26 PM, Marek Majkowski <span dir="ltr"><<a href="mailto:majek04@gmail.com" target="_blank">majek04@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div>On Mon, Nov 28, 2011 at 11:11, Roey Berman <<a href="mailto:roey.berman@gmail.com" target="_blank">roey.berman@gmail.com</a>> wrote:<br>
> Oh one fix:<br>
> self.chan.basic_publish(message, **kwargs) -> self.chan.basic_publish(body =<br>
> message, **kwargs)<br>
><br>
> On Mon, Nov 28, 2011 at 1:08 PM, Roey Berman <<a href="mailto:roey.berman@gmail.com" target="_blank">roey.berman@gmail.com</a>> wrote:<br>
>><br>
>> Thanks for the quick reply.<br>
>> At first I used the code from the example you referred me to but it<br>
>> doesn't handle the "multiple" flag and NAcks from the server.<br>
>> I know my code handles the "multiple" flag, but don't know about NAcks.<br>
>> I don't really know how to test for nacks since I've never gotten them<br>
>> from rabbitmq server.<br>
<br>
</div><a href="http://www.rabbitmq.com/extensions.html#publishing" target="_blank">http://www.rabbitmq.com/extensions.html#publishing</a><br>
<br>
"In exceptional cases when the broker is unable to handle messages<br>
successfully, instead of a basic.ack, the broker will send a<br>
basic.nack. In this context, fields of the basic.nack have the same<br>
meaning as the corresponding ones in basic.ack and the requeue field<br>
should be ignored. By nack'ing one or more messages, the broker<br>
indicates that it was unable to process the messages and refuses<br>
responsibility for them; at that point, the client may choose to<br>
re-publish the messages.<br>
<br>
After a channel is put into confirm mode, all subsequently published<br>
messages will be confirmed or nack'd once. No guarantees are made as<br>
to how soon a message is confirmed. No message will be both confirmed<br>
and nack'd."<br>
<br>
That's all I know.<br>
<div><br>
<br>
>> Once I know my code handles all responses correctly I will create a pull<br>
>> request for the pika example code.<br>
<br>
</div>Good!<br>
<span><font color="#888888"><br>
Marek<br>
</font></span><div><div><br>
<br>
>> On Mon, Nov 28, 2011 at 1:01 PM, Marek Majkowski <<a href="mailto:majek04@gmail.com" target="_blank">majek04@gmail.com</a>><br>
>> wrote:<br>
>>><br>
>>> Hi,<br>
>>><br>
>>> I'm not sure if it works - but the pika example showing<br>
>>> publisher confirms usage looks rather similar:<br>
>>><br>
>>><br>
>>> <a href="https://github.com/pika/pika/blob/120fdea5913e7ed80536ff55634ab0f8f4554e79/examples/demo_send_confirmed.py" target="_blank">https://github.com/pika/pika/blob/120fdea5913e7ed80536ff55634ab0f8f4554e79/examples/demo_send_confirmed.py</a><br>
>>><br>
>>> Cheer,<br>
>>> Marek<br>
>>><br>
>>> On Sun, Nov 27, 2011 at 15:20, bergundy <<a href="mailto:roey.berman@gmail.com" target="_blank">roey.berman@gmail.com</a>> wrote:<br>
>>> > Hi everyone,<br>
>>> ><br>
>>> > I couldn't find code for implementing publisher confirmations.<br>
>>> ><br>
>>> > I wrote this piece of code using pika 0.9.5 (python client).<br>
>>> > Would like to get feedback on this, I hope I got it right ...<br>
>>> ><br>
>>> > ---<br>
>>> > class ConfirmingProducer(object):<br>
>>> > def __init__(self, channel):<br>
>>> > self.delivery_tag = 1<br>
>>> > self.acked = 0<br>
>>> > self._callbacks = {}<br>
>>> > self.chan = channel<br>
>>> > self.chan.confirm_delivery(self.on_delivered)<br>
>>> ><br>
>>> > def publish(self, message, callback, **kwargs):<br>
>>> > self._callbacks[self.delivery_tag] = callback<br>
>>> > self.delivery_tag += 1<br>
>>> > self.chan.basic_publish(message, **kwargs)<br>
>>> ><br>
>>> > def on_delivered(self, frame):<br>
>>> > success = isinstance(frame.method, pika.spec.Basic.Ack)<br>
>>> ><br>
>>> > if frame.method.multiple:<br>
>>> > for dtag in range(self.acked+1, frame.method.delivery_tag<br>
>>> > +1):<br>
>>> > self._callbacks.pop(dtag)(success)<br>
>>> > self.acked = frame.method.delivery_tag<br>
>>> > else:<br>
>>> > self._callbacks.pop(frame.method.delivery_tag)(success)<br>
>>> > self.acked += 1<br>
>>> > _______________________________________________<br>
>>> > rabbitmq-discuss mailing list<br>
>>> > <a href="mailto:rabbitmq-discuss@lists.rabbitmq.com" target="_blank">rabbitmq-discuss@lists.rabbitmq.com</a><br>
>>> > <a href="https://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss" target="_blank">https://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss</a><br>
>>> ><br>
>><br>
><br>
><br>
</div></div></blockquote></div><br></div></div></div></div>
</blockquote></div><br></div>