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 <[EMAIL PROTECTED]> 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 via email to