rabbitmq-java-client can't connect to the rabbitmq server. java.io.IOException @ Connection

5,113 views
Skip to first unread message

Yashonlin

unread,
Dec 17, 2014, 10:13:20 PM12/17/14
to rabbitm...@googlegroups.com
Hi all,
i have install rabbitmq server in my virtual machine, and already runs successfully for i can log in the web management.

There is my problem: 
   no matter in the virtual machine or in the host(can access the web management), rabbitmq-java-client is unable to connect to the server to receive or push messages.

I have been stuck in this problem for long, please help me if you can, and Thank you! 

Here are the codes i run in the client and the exception message:

Codes:

1. Receiver

import com.rabbitmq.client.ConnectionFactory;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.QueueingConsumer;

public class Recv {

  private final static String QUEUE_NAME = "hello";

  public static void main(String[] argv) throws Exception {

    ConnectionFactory factory = new ConnectionFactory();
    factory.setHost("vm_ip_address");
    factory.setPort(5672);
    factory.setUsername("user_name");
    factory.setPassword("password");
//    factory.setVirtualHost("rabbit@localhost");
    Connection connection = factory.newConnection();
    Channel channel = connection.createChannel();

    channel.queueDeclare(QUEUE_NAME, false, false, false, null);
    System.out.println(" [*] Waiting for messages. To exit press CTRL+C");

    QueueingConsumer consumer = new QueueingConsumer(channel);
    channel.basicConsume(QUEUE_NAME, true, consumer);

    while (true) {
      QueueingConsumer.Delivery delivery = consumer.nextDelivery();
      String message = new String(delivery.getBody());
      System.out.println(" [x] Received '" + message + "'");
    }
  }
}

2. Sender

import java.io.IOException;
import com.rabbitmq.client.AMQP;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;
import com.rabbitmq.client.MessageProperties;

public class SendDemo01 {
  private final static String QUEUE_NAME = "hello";

  public static void main(String[] args) throws IOException {
    ConnectionFactory factory = new ConnectionFactory();
    factory.setHost("vm_ip_address");
    factory.setPort(5672);
    factory.setUsername("user_name");
    factory.setPassword("password");
    Connection connection = factory.newConnection();
    Channel channel = connection.createChannel();
    channel.queueDeclare(QUEUE_NAME, false, false, false, null);
    String message = "Hello World";
    channel.basicPublish("", QUEUE_NAME, null, message.getBytes());

    System.out.println("  Sent: '" + message + "'");
    channel.close();
    connection.close();
  }
}



Exception_message:

Exception in thread "main" java.io.IOException
at com.rabbitmq.client.impl.AMQChannel.wrap(AMQChannel.java:106)
at com.rabbitmq.client.impl.AMQChannel.wrap(AMQChannel.java:102)
at com.rabbitmq.client.impl.AMQConnection.start(AMQConnection.java:348)
at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:617)
at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:639)
at com.lubby.test.Recv.main(Recv.java:20)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
Caused by: com.rabbitmq.client.ShutdownSignalException: connection error
at com.rabbitmq.utility.ValueOrException.getValue(ValueOrException.java:67)
at com.rabbitmq.utility.BlockingValueOrException.uninterruptibleGetValue(BlockingValueOrException.java:33)
at com.rabbitmq.client.impl.AMQChannel$BlockingRpcContinuation.getReply(AMQChannel.java:343)
at com.rabbitmq.client.impl.AMQConnection.start(AMQConnection.java:294)
... 8 more
Caused by: java.net.SocketTimeoutException: Timeout during Connection negotiation
at com.rabbitmq.client.impl.AMQConnection.handleSocketTimeout(AMQConnection.java:585)
at com.rabbitmq.client.impl.AMQConnection.access$600(AMQConnection.java:65)
at com.rabbitmq.client.impl.AMQConnection$MainLoop.run(AMQConnection.java:560)
at java.lang.Thread.run(Thread.java:745)


I think the problem is lying in the setting procedure, but i fail to figure it out. 

Jean-Sébastien Pédron

unread,
Dec 18, 2014, 6:49:44 AM12/18/14
to rabbitm...@googlegroups.com
On 18.12.2014 04:13, Yashonlin wrote:
> Hi all,

hi!

> i have install rabbitmq server in my virtual machine, and already runs
> successfully for i can log in the web management.
>
> There is my problem:
> no matter in the virtual machine or in the host(can access the web
> management), rabbitmq-java-client is unable to connect to the server to
> receive or push messages.
>
> ...
> factory.setHost("vm_ip_address");

Do you use the same hostname/IP address to connect to the management UI?

I don't see anything wrong with the factory.set* calls. Are you sure you
don't have network configuration issues?

Some things you could check:
o Use netstat(1) on the RabbitMQ VM to see if RabbitMQ is
listenning on TCP port 5672.
o Verify your firewall settings in the VM and on your host, if you
run one.
o If you use a hostname (not an IP address) to connect, verify you
don't face an IPv4 vs. IPv6 situation (eg. you access the
management UI through IPv4, but your Java client is using IPv6).

Also, could you please post the output of "rabbitmqctl report"?

--
Jean-Sébastien Pédron
Pivotal / RabbitMQ

Yashonlin

unread,
Dec 18, 2014, 9:51:07 PM12/18/14
to rabbitm...@googlegroups.com
Thank you very much!

Actually I use both the same ip address and port number to log in via broswer and the java program. So the problem is the port for the management UI is not the same as the one RabbitMQ is listening on, it is 5772 rather than 5672. There is no doubt that i can log in the management UI but fail to connect to the server via java client. How foolish i am!  

But there is some problem disturbing me:

1. With the vm starting, the iptables rules i set up could not start automatically, and i could not find out which file the firewall start with.

2. After i start the iptable rules set up by myself where i didnt set the port 5772 as ACCEPT, but it still could be accessed. 

I am new to internet work, maybe something i put forward with is rather stupid, but if you could offer me a hand, i would appreciate it very much!

Thank you!!!

在 2014年12月18日星期四UTC+8上午11时13分20秒,Yashonlin写道:

Jean-Sébastien Pédron

unread,
Dec 19, 2014, 3:44:27 AM12/19/14
to rabbitm...@googlegroups.com
On 19.12.2014 03:51, Yashonlin wrote:
> 1. With the vm starting, the iptables rules i set up could not start
> automatically, and i could not find out which file the firewall start with.

You should refer to the documentation of your Linux distribution to
configure services and features at startup, it's quite vendor-dependent.

> 2. After i start the iptable rules set up by myself where i didnt set
> the port 5772 as ACCEPT, but it still could be accessed.

I don't know iptables configuration, but there may a default accept/deny
setting for packets who match no rule. You can find extensive
documentation and tutorials on iptables.

Joshna K

unread,
May 18, 2017, 1:01:33 AM5/18/17
to rabbitmq-users, jean-se...@rabbitmq.com
HI

I am facing issue while connecting to Rabbit MQ on pivotal, and seeing this issue
java.io.IOException
at com.rabbitmq.client.impl.AMQChannel.wrap(AMQChannel.java:106)
at com.rabbitmq.client.impl.AMQChannel.wrap(AMQChannel.java:102)
at com.rabbitmq.client.impl.AMQConnection.start(AMQConnection.java:360)
at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:516)
at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:533)
at com.tmobile.orders.preprocessor.common.SendMessage.main(SendMessage.java:19)
Caused by: com.rabbitmq.client.ShutdownSignalException: connection error; reason: java.net.SocketTimeoutException: Timeout during Connection negotiation
at com.rabbitmq.utility.ValueOrException.getValue(ValueOrException.java:67)
at com.rabbitmq.utility.BlockingValueOrException.uninterruptibleGetValue(BlockingValueOrException.java:33)
at com.rabbitmq.client.impl.AMQChannel$BlockingRpcContinuation.getReply(AMQChannel.java:343)
at com.rabbitmq.client.impl.AMQConnection.start(AMQConnection.java:313)
... 3 more
Caused by: java.net.SocketTimeoutException: Timeout during Connection negotiation
at com.rabbitmq.client.impl.AMQConnection.handleSocketTimeout(AMQConnection.java:566)
at com.rabbitmq.client.impl.AMQConnection.access$500(AMQConnection.java:59)
at com.rabbitmq.client.impl.AMQConnection$MainLoop.run(AMQConnection.java:541)

Michael Klishin

unread,
May 18, 2017, 5:27:38 AM5/18/17
to rabbitm...@googlegroups.com, Jean-Sébastien Pédron
Hi Joshna,

Please start new threads for new questions.

All the exceptions says is that there was a TCP connection timeout. Consider re-staging
your app on "Pivotal" (PWS?).

--
You received this message because you are subscribed to the Google Groups "rabbitmq-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rabbitmq-users+unsubscribe@googlegroups.com.
To post to this group, send email to rabbitmq-users@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
MK

Staff Software Engineer, Pivotal/RabbitMQ
Reply all
Reply to author
Forward
0 new messages