Hello <span class="gD">Marek,<br><br>Thanks for finding that annoying bug! Excellent!<br><br>In regards to publisher confirms, am I understanding correctly that to implement this with Net::Rabbitmq, I simply need to set no_ack => 0 (enabling acks), and then check for a defined delivery_tag, and if it is defined, then return ack, as so:<br>
<br> if ($consume_vars->{no_ack} == 0 && defined($msg->{delivery_tag}))<br> {<br> #send the ack that the message was received successfully and return<br> eval{<br>
$self->{_rabbit}->ack($self->{_channel}, $msg->{delivery_tag}, 0);<br> }; if ($@) { error_handler($self, "ack - $@"); }<br> }<br><br>Otherwise it wont return an ack and I assume stay in the queue. I haven't figured out how I would go about testing this other than perhaps timing the shut down of a consumer while it is consuming the message.<br>
<br>Thanks much for the tips!<br><br>-James<br></span><br><div class="gmail_quote">On Wed, Apr 4, 2012 at 3:57 AM, Marek Majkowski <span dir="ltr"><<a href="mailto:majek04@gmail.com">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 class="im">On Tue, Apr 3, 2012 at 17:22, iceblaze <<a href="mailto:iceblaze@gmail.com">iceblaze@gmail.com</a>> wrote:<br>
> Thanks for attempting to assist me here. I have made a light version of the<br>
> module and a sender script as you requested. You can find the files here:<br>
><br>
> <a href="http://iceblaze.com/rabbit.zip" target="_blank">http://iceblaze.com/rabbit.zip</a><br>
><br>
> Simply unzip the files into the same directory and run the "<a href="http://sender.pl" target="_blank">sender.pl</a>"<br>
> script. Note that you will need to install Net::RabbitMQ from CPAN. You can<br>
> also modify the login credentials for rabbit (right now its just using<br>
> guest/guest) in $self of Rabbit.pm's new() function:<br>
><br>
> my $self =<br>
> {<br>
> _rabbit => Net::RabbitMQ->new(),<br>
> _rabbit_user => "guest",<br>
> _rabbit_pass => "guest",<br>
> _rabbit_host => "localhost",<br>
> _rabbit_port => 5672,<br>
> _queue => $queue,<br>
> _channel => $channel,<br>
> _no_ack => $no_ack,<br>
> _queue_declared => '',<br>
> };<br>
<br>
</div>Oh, installing Net::RabbitMQ from CPAN wasn't easy at all!<br>
But in the end after few attempts "cpan; notest install Net::RabbitMQ"<br>
did the trick.<br>
<br>
So, the problem is that in your code the "delivery_mode => 2"<br>
doesn't work.<br>
<br>
(btw, I debugged your issue by using the management plugin and<br>
getting a message from the queue using it - it clearly shows<br>
that "delivery_mode" is not set)<br>
<br>
Reading the docs:<br>
<a href="http://search.cpan.org/%7Ejesus/Net--RabbitMQ-0.2.2/RabbitMQ.pm" target="_blank">http://search.cpan.org/~jesus/Net--RabbitMQ-0.2.2/RabbitMQ.pm</a><br>
<br>
publish($channel, $routing_key, $body, $options, $props)<br>
[...]<br>
$props is an optional hash (the AMQP 'props') respecting the<br>
following keys: { content_type => $string, content_encoding =><br>
$string, correlation_id => $string, reply_to => $string, expiration =><br>
$string, message_id => $string, type => $string, user_id => $string,<br>
app_id => $string, delivery_mode => $integer, priority => $integer,<br>
timestamp => $integer, }<br>
<br>
So, "delivery_mode" is a feature of "props", not "options".<br>
Appropriate code should therefore look like:<br>
<br>
$self->{_rabbit}->publish($self->{_channel}, $self->{_queue},<br>
$data, {mandatory => 1, immediate => 0 }, {delivery_mode => 2});<br>
<br>
<br>
Additionally, if you want to shield against broker falling down,<br>
and have a reliable message delivery you should be using<br>
transactions or publish confirms.<br>
<br>
By default sending messages in rabbit is asynchronous. You don't know<br>
when the message reached the broker and even if it did so.<br>
Rabbit recognizes this and it doesn't immediately flush messages<br>
to disk. Actually it will be quire reluctant to save them on disk<br>
(this has been tweaked in RabbitMQ 2.8.0).<br>
<br>
If you wish to make sure that Rabbit indeed handled messages<br>
reliably, you must use transactions or publisher confirms to<br>
get a confirmation of delivery from the broker.<br>
Once the confirmation is received you can be sure the messages<br>
are safe.<br>
<br>
On the other hand if you are only going to be closing rabbit<br>
gracefully (via the init scripts), setting the "delivery_mode"<br>
properly should be enough to persist your messages.<br>
<span class="HOEnZb"><font color="#888888"><br>
Marek<br>
</font></span></blockquote></div><br><br clear="all"><br>-- <br>"Of course, the actual government of any computer is run by that fascist dictator known as the operating system. But a wise dictator knows when to let the people think they're capitalists--and when to let them think they're communists." - Programming Perl third edition<br>