From users-return-32387-apmail-activemq-users-archive=activemq.apache.org@activemq.apache.org Thu Nov 1 20:14:28 2012 Return-Path: X-Original-To: apmail-activemq-users-archive@www.apache.org Delivered-To: apmail-activemq-users-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id D088ADEF0 for ; Thu, 1 Nov 2012 20:14:28 +0000 (UTC) Received: (qmail 67541 invoked by uid 500); 1 Nov 2012 20:14:28 -0000 Delivered-To: apmail-activemq-users-archive@activemq.apache.org Received: (qmail 67505 invoked by uid 500); 1 Nov 2012 20:14:28 -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 67497 invoked by uid 99); 1 Nov 2012 20:14:28 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 01 Nov 2012 20:14:28 +0000 X-ASF-Spam-Status: No, hits=1.5 required=5.0 tests=HTML_MESSAGE,RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of fulko.hew@gmail.com designates 209.85.217.171 as permitted sender) Received: from [209.85.217.171] (HELO mail-lb0-f171.google.com) (209.85.217.171) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 01 Nov 2012 20:14:23 +0000 Received: by mail-lb0-f171.google.com with SMTP id m4so2232980lbo.2 for ; Thu, 01 Nov 2012 13:14:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=8z7UH52gOBXKedSuRyhEXxxDDO+drxnqMYLYfdEFZaA=; b=XuoAmHz8rJ1nnLNkVvuZecGeAZDgLeUWPiyhrMChm7GzVerLQcgUtF+wL0xTc8GAun /on8xPVwIi4yCOLlfY4jRjXUWqPSg8RG15Pi7E+Yqz8FFPBGVjrJAxyS6SGUlIykdi1r 7FI/VzBorpo3vDjQmtUJ2IW+Dipc8R4G03PTKHeqYOj0igCDzmwgZFK3V1FWWWO7v1IM 0CzY6PMX4JrANzkLv36ivOaAtu2ztNPLiIPJyZhIkv/93ryCyc5KgOa2VP4pue0I4kxS ZkOVea4T4J2+fcDvz8SnRZJKRdcZ8i4TOdHAGaVBGBP4BKRllCDs9Tw3kXfN6974ifrV g3+w== Received: by 10.152.105.174 with SMTP id gn14mr37787383lab.55.1351800841540; Thu, 01 Nov 2012 13:14:01 -0700 (PDT) MIME-Version: 1.0 Received: by 10.112.74.161 with HTTP; Thu, 1 Nov 2012 13:13:40 -0700 (PDT) In-Reply-To: References: From: Fulko Hew Date: Thu, 1 Nov 2012 16:13:40 -0400 Message-ID: Subject: Re: need example for Perl STOMP access to ActiveMQ.Statistics.Broker To: users Content-Type: multipart/alternative; boundary=f46d040714c9f795bd04cd74a829 X-Virus-Checked: Checked by ClamAV on apache.org --f46d040714c9f795bd04cd74a829 Content-Type: text/plain; charset=ISO-8859-1 On Thu, Nov 1, 2012 at 3:54 PM, Christian Posta wrote: > For your Java client, the header needs to be "reply-to" per the docs here: > http://activemq.apache.org/stomp.html > Thanks, I also just recently discovered that mistake and am now getting data... My next issue is the 'encoding/transformation to specify and how to decode it into a usable hash, or equivalent. My current code is: use AnyEvent; use AnyEvent::STOMP; my $host = 'localhost'; my $port = undef; my $ack = undef; my $destination = '/queue/ActiveMQ.Statistics.Broker'; my $replyto = '/queue/statsresults'; my $once = 0; my $client = AnyEvent::STOMP->connect( $host, $port, $ssl, $replyto, $ack, undef, { receipt => '', transformation => 'jms-map-json', } ); $client->reg_cb(MESSAGE => sub { my (undef, $body, $headers) = @_; print "received 'a message', body:\n$body\n\n"; # insert body decoding here }); $client->reg_cb(frame => sub { my (undef, $type, $body, $headers) = @_; print "received $type:\nbody:\n\n"; # do something with the frame if ($type eq 'RECEIPT') { unless ($once) { $client->send('', $destination, { 'reply-to' => $replyto, receipt => '',} ); $once = 1; } } }); AnyEvent->condvar->recv; # start the event loop Additionally, pass "null" for the "transaction" parameter of the > connection.send() command if you're not going to use transactions (not > needed for this example.. but if you just use the empty string, it'll still > put the header in the SEND frame and will be interpreted incorrectly). > > I can work on an example when I get a sec.. > > Hope that helps > > On Thu, Nov 1, 2012 at 11:27 AM, Fulko Hew wrote: > > > I'm new to ActiveMQ and STOMP and am trying to get a simple example to > > work in order to retrieve system and queue information from a running > > server. > > > > I have read the information on: Apache > > ActiveMQ > Connectivity > Protocols > Stomp > > and I have enabled STOMP inside ActiveMQ. I know this works because I > was > > able to use > > the STOMP example provide in ActiveMQ. > > > > I have also read Apache > > ActiveMQ > Features > Interceptors > StatisticsPlugin and > > tested it using a version of the (non-STOMP) code I found at: > > > > > > > http://rajdavies.blogspot.ca/2009/10/query-statistics-for-apache-activemq.html > > > > So I know STOMP works, and I know the stats works, > > but I haven't gotten a Java based STOMP app (retrieving stats) to work > yet, > > or (my ultimate goad) a Perl (AnyEvent::Stomp) based app either. > > > > So far, below is my best attempt at a Perl example > > and below that is my non-working Java attempt. > > > > Does anyone have a working example of either language that I can start > from > > and learn from; or can anyone tell me what I'm missing or doing wrong? > > > > TIA > > Fulko > > > > > > use AnyEvent; > > use AnyEvent::STOMP; > > > > my $host = 'localhost'; > > my $port = undef; > > my $ack = undef; > > my $destination = '/queue/ActiveMQ.Statistics.Broker'; > > my $replyto = '/queue/statsresults'; > > my $once = 0; > > > > my $client = AnyEvent::STOMP->connect( > > $host, $port, $ssl, $replyto, $ack, > > undef, > > { > > receipt => '', > > transformation => 'jms-map-json', > > } > > ); > > > > $client->reg_cb(MESSAGE => sub { > > my (undef, $body, $headers) = @_; > > print "received something, body:\n$body\n"; > > }); > > > > $client->reg_cb(frame => sub { > > my (undef, $type, $body, $headers) = @_; > > > > print "received anything, type: $type\nbody:\n"; > > if ($type eq 'RECEIPT') { > > unless ($once) { > > $client->send('', $destination, { replyTo => $replyto, > receipt > > => ''} ); # trigger an exchange > > $once = 1; > > } > > } > > }); > > > > AnyEvent->condvar->recv; # start the event loop > > > > > > import org.apache.activemq.transport.stomp.Stomp; > > import org.apache.activemq.transport.stomp.StompConnection; > > import org.apache.activemq.transport.stomp.StompFrame; > > import org.apache.activemq.transport.stomp.Stomp.Headers.Subscribe; > > import java.util.HashMap; > > > > public class StompStats { > > > > public static void main(String args[]) throws Exception { > > > > HashMap headers = new HashMap(); > > headers.put("replyTo", "/queue/statsresults"); > > > > StompConnection connection = new StompConnection(); > > connection.open("localhost", 61613); > > connection.connect("system", "manager"); > > > > connection.subscribe("/queue/statsresults"); > > > > connection.send("/queue/ActiveMQ.Statistics.Broker", "", "", > > headers); > > > > StompFrame message = connection.receive(); > > System.out.println(message.getBody()); > > > > connection.disconnect(); > > } > > > > } > > > > > > -- > *Christian Posta* > http://www.christianposta.com/blog > twitter: @christianposta > --f46d040714c9f795bd04cd74a829--