activemq-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Friedrich Clausen" <>
Subject Using Perl to check ActiveMQ with Net::Stomp.
Date Tue, 19 Aug 2008 09:30:04 GMT
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:

* - This would push a message onto a monitoring queue.
* - This would consume the message from the monitoring
queue placed by

If does not receive the message sent by or
cannot connect then an alert is raised. I realise that there may be
some added complexity in making sure that 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!



*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";

View raw message