RabbitMQ new connection refused due to SocketException
Asked Answered
S

5

21

while trying to create a new connection to rabbitmq running on a different server, I got the following error:

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.AMQChannel.exnWrappingRpc(AMQChannel.java:124)
at com.rabbitmq.client.impl.AMQConnection.start(AMQConnection.java:406)
at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:516)
at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:533)


Caused by: com.rabbitmq.client.ShutdownSignalException: connection error; reason: java.net.SocketException: Connection reset


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.AMQChannel.privateRpc(AMQChannel.java:216)
at com.rabbitmq.client.impl.AMQChannel.exnWrappingRpc(AMQChannel.java:118)



Caused by: java.net.SocketException: Connection reset
at java.net.SocketInputStream.read(Unknown Source)
at java.net.SocketInputStream.read(Unknown Source)
at java.io.BufferedInputStream.fill(Unknown Source)
at java.io.BufferedInputStream.read(Unknown Source)
at java.io.DataInputStream.readUnsignedByte(Unknown Source)
at com.rabbitmq.client.impl.Frame.readFrom(Frame.java:95)
at com.rabbitmq.client.impl.SocketFrameHandler.readFrame(SocketFrameHandler.java:131)
at com.rabbitmq.client.impl.AMQConnection$MainLoop.run(AMQConnection.java:533)

Steps taken :

  • rabbitmq is running on the server.
  • server is specified
  • default port is specified

lsof -i tcp:5672

COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME

beam.smp 3084 rabbitmq 15u IPv6 18611 0t0 TCP *:amqp (LISTEN)

rabbitmqctl list_connections

Listing connections ... guest client_server 55765 running ...done.

netstat -tapnl | grep 5672

tcp 0 0 0.0.0.0:15672 0.0.0.0:* LISTEN 3084/beam.smp

tcp 0 0 0.0.0.0:55672 0.0.0.0:* LISTEN 3084/beam.smp

tcp 0 0 :::5672 :::* LISTEN 3084/beam.smp

Shortchange answered 3/4, 2014 at 11:0 Comment(6)
Which RabbitMQ version?Vitrify
rabbitmq version : 3.0.4 and the server is running on a centos machine.Shortchange
1. Does it work in local host? could be a firewall problem. 2. Try to execute rabbitmqctl list_connections on the server, you could have too many open connections.Vitrify
Yes it works in localhost . I tried a simple producer-consumer program. I also executed the rabbitmqctl list_connections command and got only two ports in the list and rabbitmqctl list-queues command listed only two queues currently .I restarted rabbitmq server and tried afresh , to no result . Firewall is not a problem .I have verified . Any other bottle-necks I might be missing ? Thanks in advance .Shortchange
I think it's a tcp socket problem! Did you try telnet your_server 5672 from the client ?Vitrify
yea i think that is the problem ! telnet your_server 5672 gives the following result : Trying your_server... Connected to your_server. Escape character is '^]'. Connection closed by foreign host.Shortchange
C
23

One of the possible reasons is that user you are connecting with to RabbitMQ has no rights to access to virtual hosts.

You can check this using Management Plugin (Admin tab).

Cembalo answered 12/8, 2014 at 11:24 Comment(0)
G
6
  • Do not specify the default port as you have mentioned in your steps.

  • If you have not created virtual host on the actual server, where you are trying to connect, Do create a virtual host and give it admin permision.

  • Set the virtual host on the factory before creating the new connection, like factory.setVirtualHost("VIRTUAL_HOST_NAME_ON_SERVER");

  • Make sure username on the server on which you are trying to connect is Admin and have access to the Virtual Host you just created.

  • Specify your username and password along with virtual host, while getting the connection.

  • Start your application in Debug Mode, and check if it now passes, factory.newConection();

This should make your things work. Got the same exception, and it worked for me.

If it still does not work paste your code snippet.

Gyromagnetic answered 19/2, 2015 at 1:47 Comment(0)
J
4

Check the host and port value

In application.properties

spring.rabbitmq.host=localhost
spring.rabbitmq.port=5672
spring.rabbitmq.username=guest
spring.rabbitmq.password=guest

enter image description here

See RabbitMQ site is running on port 15672 whereas in code using amqp protocol.

Junker answered 7/1, 2020 at 10:13 Comment(0)
A
1

You can check if the SSL/TLS support is enabled. Then use the instruction useSslProtocol :

ConnectionFactory factory = new ConnectionFactory();
factory.useSslProtocol();
Andraandrade answered 10/1, 2017 at 11:35 Comment(0)
C
0

In my scene, I create a rabbitmq-server on hostA, then start a client on hostB and try to connect the rabbitmq on hostA. I got Unable to connect to AMQP server error when create a new connection. It is due to the firewall. I solved it by execute command systemctl stop firewalld.

Coy answered 28/1, 2023 at 8:49 Comment(1)
As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.Malleus

© 2022 - 2025 — McMap. All rights reserved.