Quantcast

Using Perl to check ActiveMQ with Net::Stomp.

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Using Perl to check ActiveMQ with Net::Stomp.

ftclausen
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";
   }
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

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

Llarian
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:[hidden email]]
> Sent: Tuesday, August 19, 2008 2:30 AM
> To: [hidden email]
> 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";
>    }
>
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

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

Roger Hoover
In reply to this post by ftclausen
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 <[hidden email]> 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";
>   }
>
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

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

Roger Hoover
Sorry.  The syntax is.

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

On Wed, Aug 20, 2008 at 3:10 PM, Roger Hoover <[hidden email]>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 <[hidden email]> 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";
>>   }
>>
>
>
Loading...