Java 由于 SocketException,RabbitMQ 新连接被拒绝

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22835494/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 18:13:05  来源:igfitidea点击:

RabbitMQ new connection refused due to SocketException

javaconnectionrabbitmqamqp

提问by rasika vijay

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

在尝试创建与在不同服务器上运行的 rabbitmq 的新连接时,我收到以下错误:

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
  • rabbitmq 正在服务器上运行。
  • 服务器已指定
  • 指定了默认端口

lsof -i tcp:5672

lsof -i tcp:5672

COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME

命令 PID 用户 FD 类型 设备大小/关闭节点名称

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

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

rabbitmqctl list_connections

rabbitmqctl list_connections

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

列出连接...guest client_server 55765 正在运行...完成。

netstat -tapnl | grep 5672

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:15672 0.0.0.0:* 听 3084/beam.smp

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

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

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

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

回答by Denis Makarskiy

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

可能的原因之一是您连接到 RabbitMQ 的用户无权访问虚拟主机。

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

您可以使用管理插件(管理选项卡)检查这一点。

回答by user4338724

  • 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();

  • 不要指定您在步骤中提到的默认端口。

  • 如果您尚未在尝试连接的实际服务器上创建虚拟主机,请创建一个虚拟主机并授予其管理员权限。

  • 在创建新连接之前在工厂上设置虚拟主机,如 factory.setVirtualHost("VIRTUAL_HOST_NAME_ON_SERVER");

  • 确保您尝试连接的服务器上的用户名是 Admin,并且可以访问您刚刚创建的虚拟主机。

  • 在获取连接的同时指定您的用户名和密码以及虚拟主机。

  • 在调试模式下启动您的应用程序,并检查它现在是否通过, 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.

如果它仍然不起作用,请粘贴您的代码片段。

回答by pauline

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

您可以检查是否启用了 SSL/TLS 支持。然后使用指令 useSslProtocol :

ConnectionFactory factory = new ConnectionFactory();
factory.useSslProtocol();

回答by Atul Jain

Check the host and port value

检查主机和端口值

In application.properties

在 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.

请参阅 RabbitMQ 站点在端口 15672 上运行,而在使用 amqp 协议的代码中。