<html dir="ltr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style id="owaParaStyle" type="text/css">
<!--
p
        {margin-top:0;
        margin-bottom:0}
-->
</style>
</head>
<body>
<div style="direction:ltr; font-family:Tahoma; color:#000000; font-size:10pt"> I am experiencing a problem that I have been unable to pin down. When I attempt to use a java class to listen for messages bound to a particular exchange by a particular routing
key, I get a "Connection timed out" error. Here is my code:<br>
<br>
<br>
public class ReceiveLogsDirect {<br>
<br>
private static final String EXCHANGE_NAME = "ABC_SERVER";<br>
<br>
public static void main(String[] argv) throws Exception {<br>
<br>
String hostName = "localhost";<br>
int portNumber = 5672;<br>
<br>
if (argv.length < 1 || argv.length == 2 || argv.length > 3){<br>
System.err.println("Usage: ReceiveLogsDirect [session ID] [RabbitMQ server IP, optional] [RabbitMQ server port #, optional]");<br>
System.exit(1);<br>
}<br>
else if (argv.length == 1) {<br>
hostName = "localhost";<br>
portNumber = 5672; // default port that rabbitMQ listens to<br>
}<br>
else if (argv.length == 3) {<br>
hostName = argv[1];<br>
portNumber = Integer.parseInt(argv[2]);<br>
} <br>
<br>
ConnectionFactory factory = new ConnectionFactory();<br>
<br>
<br>
factory.setHost(hostName);<br>
factory.setPort(portNumber);<br>
factory.setUsername("guest");<br>
factory.setPassword("guest");<br>
factory.setVirtualHost("/");<br>
<br>
System.out.println(" [*] HERE 1");<br>
Connection connection = factory.newConnection();<br>
System.out.println(" [*] HERE 2");<br>
Channel channel = connection.createChannel(); <br>
<br>
<br>
channel.exchangeDeclare(EXCHANGE_NAME, "direct");<br>
String queueName = channel.queueDeclare().getQueue();<br>
<br>
channel.queueBind(queueName, EXCHANGE_NAME, argv[0]);<br>
System.out.println(" [*] bindingKey " + argv[0] + " is bound to queue on exchange " + EXCHANGE_NAME );<br>
<br>
System.out.println(" [*] Waiting for messages. To exit press CTRL+C");<br>
<br>
QueueingConsumer consumer = new QueueingConsumer(channel);<br>
channel.basicConsume(queueName, true, consumer);<br>
<br>
while (true) {<br>
QueueingConsumer.Delivery delivery = consumer.nextDelivery();<br>
String message = new String(delivery.getBody());<br>
String routingKey = delivery.getEnvelope().getRoutingKey();<br>
<br>
System.out.println(" [x] Received message for " + routingKey + " >>>" + message);<br>
} <br>
}<br>
<br>
I used simple print statements to pinpoint the source of the problem at the line where I call newConnection().<br>
<br>
The error I get is this: <br>
<br>
[*] HERE 1<br>
Exception in thread "main" java.net.ConnectException: Connection timed out: connect<br>
at java.net.PlainSocketImpl.socketConnect(Native Method)<br>
at java.net.PlainSocketImpl.doConnect(Unknown Source)<br>
at java.net.PlainSocketImpl.connectToAddress(Unknown Source)<br>
at java.net.PlainSocketImpl.connect(Unknown Source)<br>
at java.net.SocksSocketImpl.connect(Unknown Source)<br>
at java.net.Socket.connect(Unknown Source)<br>
at com.rabbitmq.client.ConnectionFactory.createFrameHandler(ConnectionFactory.java:441)<br>
at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:480)<br>
at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:509)<br>
at com.tasc.prism.queue.ReceiveLogsDirect.main(ReceiveLogsDirect.java:55)<br>
<br>
My install of rabbitMQ is 2.7.0. Oddly, I have been able to execute this in another command shell window and it works. I am wondering why I'm having trouble in the second shell? Surely I must be able to execute multiple instances of ReceiveLogsDirect simultaneously,
right?<br>
<br>
Could it be a runtime environment problem? I set my class path exactly the same in both shells.<br>
<br>
Any thoughts or similar experience with such a problem? Thank you.<br>
<br>
- Jim<br>
<br>
<br>
</div>
<p><font size="1" face="arial" color="gray">CONFIDENTIALITY NOTICE: This message and any attachments or files transmitted with it (collectively, the "Message") are intended only for the addressee and may contain information that is privileged, proprietary and/or
prohibited from disclosure by law or contract. If you are not the intended recipient: (a) please do not read, copy or retransmit the Message; (b) permanently delete and/or destroy all electronic and hard copies of the Message; (c) notify us by return email;
and (d) you are hereby notified that any dissemination, distribution or copying of the Message is strictly prohibited.
</font></p>
</body>
</html>