Return-Path: Delivered-To: apmail-activemq-users-archive@www.apache.org Received: (qmail 40174 invoked from network); 20 Aug 2008 22:11:09 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 20 Aug 2008 22:11:09 -0000 Received: (qmail 77430 invoked by uid 500); 20 Aug 2008 22:11:06 -0000 Delivered-To: apmail-activemq-users-archive@activemq.apache.org Received: (qmail 77411 invoked by uid 500); 20 Aug 2008 22:11:06 -0000 Mailing-List: contact users-help@activemq.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: users@activemq.apache.org Delivered-To: mailing list users@activemq.apache.org Received: (qmail 77400 invoked by uid 99); 20 Aug 2008 22:11:06 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 20 Aug 2008 15:11:06 -0700 X-ASF-Spam-Status: No, hits=2.0 required=10.0 tests=HTML_MESSAGE,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of roger.hoover@gmail.com designates 209.85.217.27 as permitted sender) Received: from [209.85.217.27] (HELO mail-gx0-f27.google.com) (209.85.217.27) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 20 Aug 2008 22:10:07 +0000 Received: by gxk8 with SMTP id 8so84997gxk.14 for ; Wed, 20 Aug 2008 15:10:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to :subject:in-reply-to:mime-version:content-type:references; bh=Dr0YIHh+Xxci9zWnDCRbSbXtlIrhZjl7dZ0I7xt54OI=; b=DXUv/aSdX+V1H9NHDAK+V8o77xf7oLPutjogSVxot7AipkVncl4DRGWLADZebh2utK gezywGzFWfljZ/9kyUGtvmZaT88rgrDl1qsXN4XeEHw2wHucn+0WzTe7FTcu3IXYyYHA 0cw1AvMeOkwGTSaNmwpTig1JBzIs6sujXw34Y= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:in-reply-to:mime-version :content-type:references; b=GCU+JRdUR5ZopIz4GfBloBoSClQIt9HH2BVevPmGcwnv3cIe2ip9G7iff0QYKotWAP b2DPYiV5h7vo0mKp5eTUteiExi9wrRkksUtm2lqRIN6VWhTNcDZUXhFGvluu+HVDpYm4 9F8tE02XnZOTONp5LOksaYEU0vhNC8lJa8efc= Received: by 10.150.205.20 with SMTP id c20mr853306ybg.196.1219270235551; Wed, 20 Aug 2008 15:10:35 -0700 (PDT) Received: by 10.150.215.9 with HTTP; Wed, 20 Aug 2008 15:10:35 -0700 (PDT) Message-ID: <44cb1ba30808201510o55c472b4me39d173cc5b4f9d5@mail.gmail.com> Date: Wed, 20 Aug 2008 15:10:35 -0700 From: "Roger Hoover" To: users@activemq.apache.org Subject: Re: Using Perl to check ActiveMQ with Net::Stomp. In-Reply-To: MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_35426_303963.1219270235516" References: X-Virus-Checked: Checked by ClamAV on apache.org ------=_Part_35426_303963.1219270235516 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline 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 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"; > } > ------=_Part_35426_303963.1219270235516--