You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@activemq.apache.org by Ianjl <ij...@gmail.com> on 2007/06/26 22:50:04 UTC

Java stomp subscriber, StompConnect?

The Goal
I need a Java subscriber client which runs locally.  This client needs to
connect to an ActiveMQ message broker and read messages from
stomp://WKS-W0106843:61613 (this is the local machine also) the queue is
pvcrawlerXML.

The Situation
I have a perl script that parses files on the server, packages the
information into xml messages, and passes them to the broker running on my
local machine.

I have a perl client that can read the messages so I know that the messages
reach the AMQ broker.  Here is the code for the perl subscriber:


while (1) {
      my $stomp2 = Net::Stomp->new( { hostname => 'localhost', port =>
'61613' } );
      $stomp2->connect( { login => '', passcode => '' } );
      $stomp2->subscribe(
          {   destination                 => '/queue/pvcrawlerXML',
              'ack'                          => 'client',
              'activemq.prefetchSize' => 1
          }
      );
        my $frame = $stomp2->receive_frame;
       
        my $str =  "I have consumed a message: " .$frame->body; 
	print "$str\r\n";
        
        $stomp2->ack( { frame => $frame } );
        $stomp2->disconnect;
      }


I require the same result except in Java.  My attempts so far have not
archived anything except confusion.
I have played with the ConsumerTool.java and build.xml, changing the
following:


	<property name="url" value="tcp://localhost:61616" />
	<property name="subject" value="/queue/FOO.BAR" />
to
	<property name="url" value="stomp://localhost:61613" />
	<property name="subject" value="/queue/pvcrawlerXML" />


The above change doesn't cause any exceptions ConsumerTool.java just hangs
at the 'connection.start();' call.  I assume that this is because
ConsumerTool does not support stomp.
I then started playing with ActiveMQStompConnect.java, see below:


public class ActiveMQStompConnect {

	public static void main(String[] args) {
        try {
            StompConnect connect = new StompConnect();
            String url = "stomp://localhost:61613"; <-- only change here.
            if (args.length > 0) {
                url = args[0];
            }
            connect.setConnectionFactory(new
ActiveMQConnectionFactory(url));
            connect.start();
            connect.join();
        }
        catch (Exception e) {
            System.out.println("Caught: " + e);
            e.printStackTrace();
        }
    }
}

If I run the above when my broker is running i get this error from
ActiveMQStompConnect:
Failed to bind to server socket: tcp://localhost:61613 due to:
java.net.BindException: Address already in use: JVM_Bind

Conclusion
How do I get at my messages from queue pvcrawlerXML, on the AMQ broker
listening to stomp://WKS-W0106843:61613 using a Java client? The perl
subscriber is not an option here.

Thank you for any help,

Ian
-- 
View this message in context: http://www.nabble.com/Java-stomp-subscriber%2C-StompConnect--tf3984709s2354.html#a11313547
Sent from the ActiveMQ - User mailing list archive at Nabble.com.


Re: Java stomp subscriber, StompConnect?

Posted by Ianjl <ij...@gmail.com>.
Hey Tom,

Thank you very much for your response and help.


Tom Samplonius-2 wrote:
> 
> 
>   What you are doing is fairly unclear.  It seems like you are trying to
> use the StompConnect JMS to Stomp bridge as a JMS client.  It is not a JMS
> client though.  StompConnect is messaging middle-ware.  It presents a
> Stomp protocol front-end, and translate to some other vendors JMS API. 
> Its main use is to still in front of another message broker's JMS API, and
> convert Stomp to JMS.
> 
I came to this realization late last night.  Thank you for confirming this
for me. :)


Tom Samplonius-2 wrote:
> 
>   If you want to write a messaging client in Java, you should probably use
> the JMS API.  Take a look at:
> 
> http://java.sun.com/products/jms/tutorial/
> 
> And if you are using Java, you might as well use OpenWire too.  The JMS
> API is pretty rich, in comparison to Stomp, so you can actually get status
> like queue size too.
> 
I will read this tutorial and try to apply it. Thank you again.

Tom Samplonius-2 wrote:
> 
> 
>   And you should probably check the Web Console or JConsole to see if the
> messages are actually in the queue you think they should be.  Perhaps the 
> 
This was a point that I forgot to mention in my last message.  According to
JConsole my messages are there in an AMQ queue.  This is also confirmed by
my perl subscriber that is able to consume the messages.

Tom Samplonius-2 wrote:
> 
> 
>   And a OpenWire consumer and a Stomp producer should be no problem.  But
> you should take care on your message encoding.
> 

I am under the impression that the example java consumer ConsumerTool.java
that is included in the AMQ distribution is an OpenWire consumer example, is
this correct?  

Thanks,

Ian


-- 
View this message in context: http://www.nabble.com/Java-stomp-subscriber%2C-StompConnect--tf3984709s2354.html#a11329175
Sent from the ActiveMQ - User mailing list archive at Nabble.com.


Re: Java stomp subscriber, StompConnect?

Posted by Tom Samplonius <to...@samplonius.org>.
  What you are doing is fairly unclear.  It seems like you are trying to use the StompConnect JMS to Stomp bridge as a JMS client.  It is not a JMS client though.  StompConnect is messaging middle-ware.  It presents a Stomp protocol front-end, and translate to some other vendors JMS API.  Its main use is to still in front of another message broker's JMS API, and convert Stomp to JMS.

  If you want to write a messaging client in Java, you should probably use the JMS API.  Take a look at:

http://java.sun.com/products/jms/tutorial/

And if you are using Java, you might as well use OpenWire too.  The JMS API is pretty rich, in comparison to Stomp, so you can actually get status like queue size too.

  And you should probably check the Web Console or JConsole to see if the messages are actually in the queue you think they should be.  Perhaps the 

  And a OpenWire consumer and a Stomp producer should be no problem.  But you should take care on your message encoding.



----- "Ianjl" <ij...@gmail.com> wrote:
> The Goal
> I need a Java subscriber client which runs locally.  This client needs
> to
> connect to an ActiveMQ message broker and read messages from
> stomp://WKS-W0106843:61613 (this is the local machine also) the queue
> is
> pvcrawlerXML.
> 
> The Situation
> I have a perl script that parses files on the server, packages the
> information into xml messages, and passes them to the broker running
> on my
> local machine.
> 
> I have a perl client that can read the messages so I know that the
> messages
> reach the AMQ broker.  Here is the code for the perl subscriber:
> 
> 
> while (1) {
>       my $stomp2 = Net::Stomp->new( { hostname => 'localhost', port
> =>
> '61613' } );
>       $stomp2->connect( { login => '', passcode => '' } );
>       $stomp2->subscribe(
>           {   destination                 => '/queue/pvcrawlerXML',
>               'ack'                          => 'client',
>               'activemq.prefetchSize' => 1
>           }
>       );
>         my $frame = $stomp2->receive_frame;
>        
>         my $str =  "I have consumed a message: " .$frame->body; 
> 	print "$str\r\n";
>         
>         $stomp2->ack( { frame => $frame } );
>         $stomp2->disconnect;
>       }
> 
> 
> I require the same result except in Java.  My attempts so far have
> not
> archived anything except confusion.
> I have played with the ConsumerTool.java and build.xml, changing the
> following:
> 
> 
> 	<property name="url" value="tcp://localhost:61616" />
> 	<property name="subject" value="/queue/FOO.BAR" />
> to
> 	<property name="url" value="stomp://localhost:61613" />
> 	<property name="subject" value="/queue/pvcrawlerXML" />
> 
> 
> The above change doesn't cause any exceptions ConsumerTool.java just
> hangs
> at the 'connection.start();' call.  I assume that this is because
> ConsumerTool does not support stomp.
> I then started playing with ActiveMQStompConnect.java, see below:
> 
> 
> public class ActiveMQStompConnect {
> 
> 	public static void main(String[] args) {
>         try {
>             StompConnect connect = new StompConnect();
>             String url = "stomp://localhost:61613"; <-- only change
> here.
>             if (args.length > 0) {
>                 url = args[0];
>             }
>             connect.setConnectionFactory(new
> ActiveMQConnectionFactory(url));
>             connect.start();
>             connect.join();
>         }
>         catch (Exception e) {
>             System.out.println("Caught: " + e);
>             e.printStackTrace();
>         }
>     }
> }
> 
> If I run the above when my broker is running i get this error from
> ActiveMQStompConnect:
> Failed to bind to server socket: tcp://localhost:61613 due to:
> java.net.BindException: Address already in use: JVM_Bind
> 
> Conclusion
> How do I get at my messages from queue pvcrawlerXML, on the AMQ
> broker
> listening to stomp://WKS-W0106843:61613 using a Java client? The perl
> subscriber is not an option here.
> 
> Thank you for any help,
> 
> Ian
> -- 
> View this message in context:
> http://www.nabble.com/Java-stomp-subscriber%2C-StompConnect--tf3984709s2354.html#a11313547
> Sent from the ActiveMQ - User mailing list archive at Nabble.com.