Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

Async Net::AMQP::RabbitMQ

by dcpetrov (Initiate)
on Jun 29, 2020 at 08:56 UTC ( #11118646=perlquestion: print w/replies, xml ) Need Help??

dcpetrov has asked for the wisdom of the Perl Monks concerning the following question:

Hey monks, I am little bit confused of all the RabbitMQ interfaces available for Perl. I'm currently using Net::RabbitFoot which has it last update back in 2011 and Net::RabbitFoot performance compared to Net::AMQP::RabbitMQ seems to be 4 times slower. So I am trying to migrate my code to Net::AMQP::RabbitMQ which uses librammitmq underneath. What I am currently struggling with, is how to run periodic task, since $mq->recv() is blocking. With Net::RabbitFoot I currently do something similar:
my $ae = AnyEvent->timer ( after => 5, interval => 60, cb => \&logStats, ); my $rf = Net::RabbitFoot->new()->load_xml_spec()->connect( host => 'localhost', port => 5672, user => 'guest', pass => 'guest', vhost => '/', timeout => 1, ); ... open channel and define on_consume handler ... AnyEvent->condvar->recv;
So I am wondering how can I achieve the same using Net::AMQP::RabbitMQ. Thanks.

Replies are listed 'Best First'.
Re: Async Net::AMQP::RabbitMQ
by haukex (Bishop) on Jun 29, 2020 at 14:45 UTC

    Because you seem to be using AnyEvent, a quick search on CPAN reveals AnyEvent::RabbitMQ, with the most recent release being this month. Although I haven't tried it myself, it may be worth a try for you.

Re: Async Net::AMQP::RabbitMQ
by Fletch (Chancellor) on Jun 29, 2020 at 15:20 UTC

    RabbitMQ supports STOMP and at $work we've had good results (for our particular application) using Net::STOMP to talk to the broker rather than going over AMQP proper. If there's an async STOMP client that works with your event loop that might be a solution.

    The cake is a lie.
    The cake is a lie.
    The cake is a lie.

Re: Async Net::AMQP::RabbitMQ
by ait (Hermit) on Jun 29, 2020 at 14:55 UTC

    Hi there dcpetrov,

    Whilst I am not familiar with the Net::AMQP::RabbitMQ particulars, is RabbitMQ your only option for MQ?

    Many times I have found that most MQ needs can easily be handled in simpler ways. For example, in Postgres 9.5 onward incorporates "skip locked" which allows you to implement simple queues right on your database rather that incorporating yet another tool, especially not one written in Java (LOL, sorry I couldn't resist) Erlang (thanks Fletch for pointing out).

    But seriously, if you happen to be using pg as your RDBMS already, or are a fan of KISS (not necessarily the rock band), PostgreSQL's native support to implement MQ can easily handle 10K TPS which is usually much more that you will need on most MQs. Not saying you can always replace a dedicated MQ system, but many times, there is rarely a need to implement a full fledged MQ. Moreover, lots of programming tasks could benefit from implementing more MQs but coders shy away because of the complexity and the need to incorporate yet another technology to your stack. For these situations, simple and native Postgres MQs are very apt.

    E.g. you can implement a queue on any table, with any structure and pop it with a simple query like so (BTW works great on DBD:Pg):

    delete from out_queue where id = (select id from out_queue order by id + for update skip locked limit 1) returning *

    Here is a good introduction:

    If you are worried about performance of Pg in general:

    There is also a specialized MQ on Pg called PGQ. I have never used it so can't comment more:

    Finally, not sure if this is still maintained but I used this POE-based MQ system many years ago and it was quite good. IIRC you don't even need to know POE to use it:

      RabbitMQ is written in Erlang; you may be thinking of ActiveMQ which is Java (and C++ maybe?).</nitpick></pedant>

      The cake is a lie.
      The cake is a lie.
      The cake is a lie.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://11118646]
Front-paged by Arunbear
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (6)
As of 2020-07-06 09:43 GMT
Find Nodes?
    Voting Booth?

    No recent polls found