[rabbitmq-discuss] Help with persistence using RabbitMQ?

iceblaze iceblaze at gmail.com
Thu Apr 5 05:12:17 BST 2012


Hello Marek,

Thanks for finding that annoying bug! Excellent!

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:

        if ($consume_vars->{no_ack} == 0 && defined($msg->{delivery_tag}))
        {
                #send the ack that the message was received successfully
and return
                eval{
                        $self->{_rabbit}->ack($self->{_channel},
$msg->{delivery_tag}, 0);
                }; if ($@) { error_handler($self, "ack - $@"); }
        }

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.

Thanks much for the tips!

-James

On Wed, Apr 4, 2012 at 3:57 AM, Marek Majkowski <majek04 at gmail.com> wrote:

> On Tue, Apr 3, 2012 at 17:22, iceblaze <iceblaze at gmail.com> wrote:
> > Thanks for attempting to assist me here. I have made a light version of
> the
> > module and a sender script as you requested. You can find the files here:
> >
> > http://iceblaze.com/rabbit.zip
> >
> > Simply unzip the files into the same directory and run the "sender.pl"
> > script. Note that you will need to install Net::RabbitMQ from CPAN. You
> can
> > also modify the login credentials for rabbit (right now its just using
> > guest/guest) in $self of Rabbit.pm's new() function:
> >
> >         my $self =
> >         {
> >                 _rabbit => Net::RabbitMQ->new(),
> >                 _rabbit_user => "guest",
> >                 _rabbit_pass => "guest",
> >                 _rabbit_host => "localhost",
> >                 _rabbit_port => 5672,
> >                 _queue => $queue,
> >                 _channel => $channel,
> >                 _no_ack => $no_ack,
> >                 _queue_declared => '',
> >         };
>
> Oh, installing Net::RabbitMQ from CPAN wasn't easy at all!
> But in the end after few attempts "cpan; notest install Net::RabbitMQ"
> did the trick.
>
> So, the problem is that in your code the "delivery_mode => 2"
> doesn't work.
>
> (btw, I debugged your issue by using the management plugin and
> getting a message from the queue using it - it clearly shows
> that "delivery_mode" is not set)
>
> Reading the docs:
> http://search.cpan.org/~jesus/Net--RabbitMQ-0.2.2/RabbitMQ.pm
>
>    publish($channel, $routing_key, $body, $options, $props)
>    [...]
>    $props is an optional hash (the AMQP 'props') respecting the
> following keys: { content_type => $string, content_encoding =>
> $string, correlation_id => $string, reply_to => $string, expiration =>
> $string, message_id => $string, type => $string, user_id => $string,
> app_id => $string, delivery_mode => $integer, priority => $integer,
> timestamp => $integer, }
>
> So, "delivery_mode" is a feature of "props", not "options".
> Appropriate code should therefore look like:
>
>    $self->{_rabbit}->publish($self->{_channel}, $self->{_queue},
> $data, {mandatory => 1, immediate => 0 }, {delivery_mode => 2});
>
>
> Additionally, if you want to shield against broker falling down,
> and have a reliable message delivery you should be using
> transactions or publish confirms.
>
> By default sending messages in rabbit is asynchronous. You don't know
> when the message reached the broker and even if it did so.
> Rabbit recognizes this and it doesn't immediately flush messages
> to disk. Actually it will be quire reluctant to save them on disk
> (this has been tweaked in RabbitMQ 2.8.0).
>
> If you wish to make sure that Rabbit indeed handled messages
> reliably, you must use transactions or publisher confirms to
> get a confirmation of delivery from the broker.
> Once the confirmation is received you can be sure the messages
> are safe.
>
> On the other hand if you are only going to be closing rabbit
> gracefully (via the init scripts), setting the "delivery_mode"
> properly should be enough to persist your messages.
>
> Marek
>



-- 
"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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.rabbitmq.com/pipermail/rabbitmq-discuss/attachments/20120404/db397838/attachment.htm>


More information about the rabbitmq-discuss mailing list