[rabbitmq-discuss] Failure to return from call to newConnection()

McMahon, James S (TASC) james.mcmahon at TASC.COM
Tue Oct 9 11:19:57 BST 2012


     Thank you for your help, Simon. I did look more closely at the situation as you suggested. It seems that I can only start one process listening to a specific port at IP address of the rabbitMQ server. I can't start the second listening to the same port at the same address.

     In one command shell, I start my listener on port 5672. It works great. I then start up a second command shell, the first still running. I tell the second instance of my listener process to listen to the same port. It never returns, and I get the connection timed out error. If I start my second process without pointing it to a port or using an IP address, it works just fine. To the untrained (ie, me), this tells me that the second works because it goes to my rabbitMQ server instance locally, rather than through IP and port.

    So in summary: two listener processes in different command shells on the same physical laptop, started from the command line. Trying to listen on the same port, to the same rabbitMQ server instance at IP. Not being familiar with port configurations and limitations, shouldn't I be able to have multiple listener processes listening to incoming on the same port? The evidence appears to say "no". Why is that?

- Jim

________________________________________
From: Simon MacMullen [simon at rabbitmq.com]
Sent: Monday, October 08, 2012 5:22 PM
To: Discussions about RabbitMQ
Cc: McMahon, James S (TASC)
Subject: Re: [rabbitmq-discuss] Failure to return from call to newConnection()

The stack trace you have posted really does look like a standard case of
the TCP connection timing out. I suggest you make absolutely sure that
you really are connecting to the host/port you think you are.

Cheers, Simon

On 08/10/2012 9:02PM, McMahon, James S (TASC) wrote:
>        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:
>
>
> public class ReceiveLogsDirect {
>
>    private static final String EXCHANGE_NAME = "ABC_SERVER";
>
>    public static void main(String[] argv) throws Exception {
>
>        String hostName = "localhost";
>        int portNumber = 5672;
>
>        if (argv.length < 1 || argv.length == 2 || argv.length > 3){
>            System.err.println("Usage: ReceiveLogsDirect [session ID]
> [RabbitMQ server IP, optional] [RabbitMQ server port #, optional]");
>            System.exit(1);
>        }
>        else if (argv.length == 1) {
>            hostName = "localhost";
>            portNumber = 5672; // default port that rabbitMQ listens to
>        }
>        else if  (argv.length == 3) {
>            hostName = argv[1];
>            portNumber = Integer.parseInt(argv[2]);
>        }
>
>        ConnectionFactory factory = new ConnectionFactory();
>
>
>        factory.setHost(hostName);
>        factory.setPort(portNumber);
>        factory.setUsername("guest");
>        factory.setPassword("guest");
>        factory.setVirtualHost("/");
>
>        System.out.println(" [*] HERE 1");
>        Connection connection = factory.newConnection();
>        System.out.println(" [*] HERE 2");
>        Channel channel = connection.createChannel();
>
>
>      channel.exchangeDeclare(EXCHANGE_NAME, "direct");
>      String queueName = channel.queueDeclare().getQueue();
>
>          channel.queueBind(queueName, EXCHANGE_NAME, argv[0]);
>          System.out.println(" [*] bindingKey " + argv[0]  +  " is bound
> to queue on exchange " + EXCHANGE_NAME );
>
>      System.out.println(" [*] Waiting for messages. To exit press CTRL+C");
>
>      QueueingConsumer consumer = new QueueingConsumer(channel);
>      channel.basicConsume(queueName, true, consumer);
>
>      while (true) {
>        QueueingConsumer.Delivery delivery = consumer.nextDelivery();
>        String message = new String(delivery.getBody());
>        String routingKey = delivery.getEnvelope().getRoutingKey();
>
>        System.out.println(" [x] Received message for " + routingKey + "
>  >>>" + message);
>      }
>    }
>
> I used simple print statements to pinpoint the source of the problem at
> the line where I call newConnection().
>
>       The error I get is this:
>
>   [*] HERE 1
> Exception in thread "main" java.net.ConnectException: Connection timed
> out: connect
>      at java.net.PlainSocketImpl.socketConnect(Native Method)
>      at java.net.PlainSocketImpl.doConnect(Unknown Source)
>      at java.net.PlainSocketImpl.connectToAddress(Unknown Source)
>      at java.net.PlainSocketImpl.connect(Unknown Source)
>      at java.net.SocksSocketImpl.connect(Unknown Source)
>      at java.net.Socket.connect(Unknown Source)
>      at
> com.rabbitmq.client.ConnectionFactory.createFrameHandler(ConnectionFactory.java:441)
>      at
> com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:480)
>      at
> com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:509)
>      at
> com.tasc.prism.queue.ReceiveLogsDirect.main(ReceiveLogsDirect.java:55)
>
>       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?
>
>      Could it be a runtime environment problem? I set my class path
> exactly the same in both shells.
>
>      Any thoughts or similar experience with such a problem? Thank you.
>
> - Jim
>
>
> 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.
>
>
>
> _______________________________________________
> rabbitmq-discuss mailing list
> rabbitmq-discuss at lists.rabbitmq.com
> https://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss
>
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.


More information about the rabbitmq-discuss mailing list