activemq-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dylan Vanderhoof <Dyl...@semaphore.com>
Subject RE: Using Perl to check ActiveMQ with Net::Stomp.
Date Wed, 20 Aug 2008 16:48:02 GMT
can_read() is actually part of IO::Select, and not at all related to the broker.

Net::Stomp's can_read function just passes through to the internal IO::Select->can_read()
function on the socket to the client, so if you want to explore what its actually doing, look
to that module instead of Net::Stomp.

That said, Net::Stomp is pretty inelegant, so it may not end up doing what you want.

-D

> -----Original Message-----
> From: Friedrich Clausen [mailto:fred@derf.nl]
> Sent: Tuesday, August 19, 2008 2:30 AM
> To: users@activemq.apache.org
> Subject: Using Perl to check ActiveMQ with Net::Stomp.
>
>
> Hello All,
>
> (Sample code of what we are trying is at the end of the email)
>
> I would like to use Net::Stomp to write a Nagios check for ActiveMQ
> and Net::Stomp looks ideal for this. The idea is like so:
>
> * send.pl() - This would push a message onto a monitoring queue.
> * receive.pl() - This would consume the message from the monitoring
> queue placed by send.pl
>
> If receive.pl does not receive the message sent by send.pl or send.pl
> cannot connect then an alert is raised. I realise that there may be
> some added complexity in making sure that receive.pl really reads the
> correct message but we would like something to get us started.
>
> However, we encountered two issues:
>
> * Net::Stomp's receive_frame() method continually waits for a new
> message to arrive on ActiveMQ. What we would like is to check if a
> specific (or any for that matter) message has arrived and then exit
> with an exit code determined by whether the aforementioned message had
> arrived or not.
>
> * So, I discovered the can_read() method - this sounded ideal as the
> documentation implied (to me at least) that if there are messages
> waiting on the queue can_read() will return a certain value. However,
> can_read() always returns the same value(0), no matter if there are
> messages on the queue or not.
>
> If anyone can shed some light on this - it would be much appreciated!
>
> Thanks,
>
> Fred.
>
> *Code follows*
>
>    my($queue) = @_;
>    my $content;
>
>    my $stomp = Net::Stomp->new( { hostname => 'localhost',
> port => '61613' } );
>    $stomp->connect( { 'login' => '', 'passcode' => '' } ) || die
> "Cannot connect to ActiveMQ Server\n";
>    $stomp->subscribe( { destination => '/queue/monitor', ack
> => 'client' } );
>
>    my $can_read = $stomp->can_read;
>    print "Can read is $can_read\n";
>    if ($can_read) {
>        print "I can read a frame\n";
>    } else {
>        print "No frames waiting\n";
>    }
>

Mime
View raw message