activemq-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christian Posta <christian.po...@gmail.com>
Subject Re: need example for Perl STOMP access to ActiveMQ.Statistics.Broker
Date Fri, 02 Nov 2012 03:27:17 GMT
So I just took a further peek... looks like the protocol converter isn't
converting the ActiveMQMapMessage which the StatisticsBroker creates into
an appropriate STOMP frame. There is some code inside the
JmsFrameTranslator that might do this, but the correct translator needs to
be picked for that. I'll investigate a little more tomorrow.

On Thu, Nov 1, 2012 at 1:13 PM, Fulko Hew <fulko.hew@gmail.com> wrote:

> On Thu, Nov 1, 2012 at 3:54 PM, Christian Posta
> <christian.posta@gmail.com>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 <fulko.hew@gmail.com> 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<String, String> headers = new HashMap<String,
> String>();
> > >         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
> >
>



-- 
*Christian Posta*
http://www.christianposta.com/blog
twitter: @christianposta

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message