[rabbitmq-discuss] Working with Java Client

Paul Jones pauljones23 at gmail.com
Fri Aug 21 21:24:34 BST 2009


Ram,

On Fri, Aug 21, 2009 at 8:31 PM, Ram Muthiah <ram.muthiah at yahoo.com> wrote:

> I am not running the client in the same machine as the server. I installed
> rabbitmq in our server. I am testing the PC clients that communicate with
> rabbitmq server. I left the username and password as it is, so their values
> are still "guest". However, the hostname is changed, so I am not able to use
> TestMain out of the box. The documentation should clearly state that
> runjava.bat com.rabbitmq.examples.TestMain would work only if the broker is
> installed in the same machine as the client.
>

A quick perusal of the source code for TestMain indicates quite quickly (and
in my opinion, relatively clearly) that the optional first command line
parameter is the target host to connect to. Specifying this will change the
host that the application connects to.

The below failure, as indicated by the NoClassFoundError, indicates that
you're missing apache commons-io, a dependency of the library. You'll need
to add that into your classpath in order for the library to work.
Alternatively, you could just run the examples with dev.rabbitmq.com as the
first parameter.

Paul.


>
> Going to the "stuck" part of my development effort -- I have the following
> code that is supposed to connect the consumer to the broker.
>
> package rabbitmq;
>
> import com.rabbitmq.client.AMQP;
> import com.rabbitmq.client.Channel;
> import com.rabbitmq.client.Connection;
> import com.rabbitmq.client.ConnectionFactory;
> import com.rabbitmq.client.QueueingConsumer;
>
> public class SimpleConsumer {
>     public static void main(String[] args) {
>         try {
>             String hostName = (args.length > 0) ? args[0] : "
> dev.rabbitmq.com";
>             int portNumber = (args.length > 1) ? Integer.parseInt(args[1])
> : AMQP.PROTOCOL.PORT;
>             String queueName = (args.length > 2) ? args[2] : "SimpleQueue";
>
>             ConnectionFactory connFactory = new ConnectionFactory();
>             Connection conn = connFactory.newConnection(hostName,
> portNumber);
>
>             final Channel ch = conn.createChannel();
>
>             ch.queueDeclare(queueName);
>
>             QueueingConsumer consumer = new QueueingConsumer(ch);
>             ch.basicConsume(queueName, consumer);
>             while (true) {
>                 QueueingConsumer.Delivery delivery =
> consumer.nextDelivery();
>                 System.out.println("Message: " + new
> String(delivery.getBody()));
>                 ch.basicAck(delivery.getEnvelope().getDeliveryTag(),
> false);
>             }
>         } catch (Exception ex) {
>             System.err.println("Main thread caught exception: " + ex);
>             ex.printStackTrace();
>             System.exit(1);
>         }
>     }
> }
>
> When I run the above code, I get the following error message:
>
> Main thread caught exception: java.io.IOException
> java.io.IOException
>         at com.rabbitmq.client.impl.AMQChannel.wrap(AMQChannel.java:121)
>         at
> com.rabbitmq.client.impl.AMQConnection.open(AMQConnection.java:363)
>         at
> com.rabbitmq.client.impl.AMQConnection.<init>(AMQConnection.java:208)
>         at
> com.rabbitmq.client.impl.AMQConnection.<init>(AMQConnection.java:178)
>         at
> com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:165)
>         at
> com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:213)
>         at
> com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:227)
>         at
> com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:238)
>         at rabbitmq.SimpleConsumer.main(SimpleConsumer.java:48)
> Caused by: com.rabbitmq.client.ShutdownSignalException: connection error;
> reason: java.lang.NoClassDefFoundError:
> org/apache/commons/io/input/ProxyInputStream
>         at
> com.rabbitmq.client.impl.AMQConnection.shutdown(AMQConnection.java:599)
>         at
> com.rabbitmq.client.impl.AMQConnection$MainLoop.run(AMQConnection.java:465)
> Caused by: java.lang.NoClassDefFoundError:
> org/apache/commons/io/input/ProxyInputStream
>         at java.lang.ClassLoader.defineClass1(Native Method)
>         at java.lang.ClassLoader.defineClass(ClassLoader.java:621)
>         at
> java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
>         at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
>         at java.net.URLClassLoader.access$000(URLClassLoader.java:56)
>         at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
>         at java.security.AccessController.doPrivileged(Native Method)
>         at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
>         at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
>         at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
>         at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
>         at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
>         at
> com.rabbitmq.client.impl.MethodArgumentReader.<init>(MethodArgumentReader.java:70)
>         at
> com.rabbitmq.client.impl.AMQImpl.readMethodFrom(AMQImpl.java:5710)
>         at
> com.rabbitmq.client.impl.AMQCommand$Assembler.handleFrame(AMQCommand.java:275)
>         at
> com.rabbitmq.client.impl.AMQChannel.handleFrame(AMQChannel.java:107)
>         at
> com.rabbitmq.client.impl.AMQConnection$MainLoop.run(AMQConnection.java:439)
> Caused by: java.lang.ClassNotFoundException:
> org.apache.commons.io.input.ProxyInputStream
>         at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
>         at java.security.AccessController.doPrivileged(Native Method)
>         at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
>         at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
>         at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
>         at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
>         at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
>
>
> What I am looking for is complete working example of java code for the
> client. Simple example like just connecting to the broker and receiving the
> message (on the consumer side) from the producer.
>
> Thanks
> Ram
>
>
> ------------------------------
> *From:* Paul Jones <pauljones23 at gmail.com>
> *To:* Ram Muthiah <ram.muthiah at yahoo.com>
> *Cc:* rabbitmq-discuss at lists.rabbitmq.com
> *Sent:* Thursday, August 20, 2009 11:07:42 AM
> *Subject:* Re: [rabbitmq-discuss] Working with Java Client
>
> Ram,
>
> On Thu, Aug 20, 2009 at 6:40 PM, Ram Muthiah <ram.muthiah at yahoo.com>wrote:
>
>> I feel the examples document needs to be more detailed. Examples page
>> instructs to run runjava.bat com.rabbitmq.examples.TestMain to run the
>> TestMain class. But, don't we need to change hostname, guest, password, etc
>> before running these classes?
>>
>
> As far as I can see, the scripts default to using localhost and
> guest/guest. A broker running on the same machine should accept these
> credentials out of the box.
>
>
>>
>> I setup the server, I ran some basic python scripts to send/receive
>> messages, they work well. I am stuck while using java client. Any help is
>> much appreciated.
>>
>
> Unfortunately you're going to need to tell us how you're stuck before we
> can provide any useful assistance.
>
> Paul.
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.rabbitmq.com/pipermail/rabbitmq-discuss/attachments/20090821/f722cfc2/attachment.htm 


More information about the rabbitmq-discuss mailing list