[rabbitmq-discuss] Failure to return from call to newConnection()
McMahon, James S (TASC)
james.mcmahon at TASC.COM
Tue Oct 9 17:11:41 BST 2012
Let me try again, more carefully applying terminology.
I've got a java class to receive messages through a direct exchange. In my class, I establish a new ConnectionFactory, factory. I use factory.setHost, under the impression that this is how I would tell it where to find my rabbitMQ server. For discussion purposes, let's say my rabbitMQ server runs on 123.456.666.6. I use factory.setPort, under the impression that this is how I indicate on which port my rabbitMQ server is listening. I've been using 5672, which I believe is the default used by rabbitMQ server.
All of the following is executed on the same physical machine, co-resident with the rabbitMQ server.
I execute my java class a first time in a command shell like this:
java -cp %CP% myClass EXCHANGE_A 123.456.666.6 5672
In that shell window, the class returns with a message that it is waiting for any messages posted to rabbitMQ for EXCHANGE_A.
In a second shell window I try to execute a second instance of this class, for a second and different directed exchange:
java -cp %CP% myClass EXCHANGE_B 123.456.666.6 5672
This is not successful. When myClass reaches the point where it tries to do this
Connection connection = factory.newConnection();
it sits there until it eventually times out.
If in that second shell window I execute the command as follows, without stipulating the IP or port
java -cp %CP% myClass EXCHANGE_B
it returns immediately, telling me that it is waiting for any messages posted to rabbitMQ for EXCHANGE_B. It was successful executing newConnection.
There's no firewall. All of these are on one physical computer for testing purposes. What am I not understanding correctly that causes this
java -cp %CP% myClass EXCHANGE_B 123.456.666.6 5672
to time out?
________________________________________
From: Simon MacMullen [simon at rabbitmq.com]
Sent: Tuesday, October 09, 2012 10:53 AM
To: McMahon, James S (TASC)
Cc: rabbitmq-discuss at lists.rabbitmq.com
Subject: Re: [rabbitmq-discuss] Failure to return from call to newConnection()
I am not quite sure what you are saying. You can only start one service
*listening* to a given port IP address combination (i.e. you can only
have one RabbitMQ *server* on a given port on a given interface). But
I'm not sure if that's what you mean by "listening". Normally we refer
to the server as "listening" and the client as "connecting".
But definitely more than one client can connect to a server on the same
IP address / port.
I'm also not sure what you mean by "it goes to my rabbitMQ server
instance locally, rather than through IP and port". Connections are
always to an IP address and port.
But "Connection timed out" means that you are trying to connect to a
host which is not responding at all, even to reject your connection
attempt - probably because there is a firewall in the way. Honestly,
that's what's happening.
Cheers, Simon
On 09/10/12 11:19, McMahon, James S (TASC) wrote:
> 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.
>
--
Simon MacMullen
RabbitMQ, VMware
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