You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@activemq.apache.org by Friedrich Clausen <fr...@derf.nl> on 2008/08/19 11:30:04 UTC

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

Re: Using Perl to check ActiveMQ with Net::Stomp.

Posted by Roger Hoover <ro...@gmail.com>.
Sorry.  The syntax is.

$stomp->can_read({'timeout' => 5});

On Wed, Aug 20, 2008 at 3:10 PM, Roger Hoover <ro...@gmail.com>wrote:

> I'm using can_read() in a similar way as you and it works.  Perhaps you're
> not waiting long enough?
>
> Try setting a timeout.
>
> #This will wait on the socket for up to 5 seconds
> my $can_read = $stomp->can_read(5);
>
>
> On Tue, Aug 19, 2008 at 2:30 AM, Friedrich Clausen <fr...@derf.nl> wrote:
>
>> 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";
>>   }
>>
>
>

Re: Using Perl to check ActiveMQ with Net::Stomp.

Posted by Roger Hoover <ro...@gmail.com>.
I'm using can_read() in a similar way as you and it works.  Perhaps you're
not waiting long enough?

Try setting a timeout.

#This will wait on the socket for up to 5 seconds
my $can_read = $stomp->can_read(5);

On Tue, Aug 19, 2008 at 2:30 AM, Friedrich Clausen <fr...@derf.nl> wrote:

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

RE: Using Perl to check ActiveMQ with Net::Stomp.

Posted by Dylan Vanderhoof <Dy...@semaphore.com>.
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";
>    }
>