RabbitMQ 连接重置

编程入门 行业动态 更新时间:2024-10-15 12:34:46
本文介绍了RabbitMQ 连接重置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试使用 java 代码将一个简单的 RabbitMQ 连接到我的服务器(正在执行 RabbitMQ 服务).执行以下代码(source here)给了我 java.SocketException:连接重置异常.

I'm trying to connect a simple RabbitMQ using java code to my server (which is executing the RabbitMQ service). Executing the following code (source here) gives me the java.SocketException: Connection Reset exception.

import java.io.*; import java.security.*; import com.rabbitmq.client.*; public class test { public static void main(String[] args) throws Exception { ConnectionFactory factory = new ConnectionFactory(); factory.setHost("myIP"); //myIP is just dummy text, I have a real IP there factory.setPort(5672); factory.setUsername("admin"); factory.setPassword("sesgo"); factory.setVirtualHost("vSESGO"); factory.useSslProtocol(); Connection conn = factory.newConnection(); Channel channel = conn.createChannel(); channel.queueDeclare("rabbitmq-java-test", false, true, true, null); channel.basicPublish("", "rabbitmq-java-test", null, "Hello, World".getBytes()); GetResponse chResponse = channel.basicGet("rabbitmq-java-test", false); if(chResponse == null) { System.out.println("No message retrieved"); } else { byte[] body = chResponse.getBody(); System.out.println("Recieved: " + new String(body)); } channel.close(); conn.close(); } }

我已经在网上寻找答案并且已经尝试过:

I've looked for an answer online and I've already tried:

  • 验证服务器是否打开了我要连接的端口.
  • 验证客户端不会阻止我与防火墙等的连接.
  • 在 RabbitMQ 上创建一个新的虚拟主机并为其授予权限.
  • 验证 iptables 不会在服务器端阻止我.
  • 似乎没有任何效果,有什么想法吗?

    Nothing seems to work, any ideas?

    完整的堆栈跟踪:

    This trust manager trusts every certificate, effectively disabling peer verification. This is convenient for local development but prone to man-in-the-middle attacks. Please see www.rabbitmq/ssl.html#validating-cerficates to learn more about peer certificate validation. Exception in thread "main" java.SocketException: Connection reset at java.SocketInputStream.read(Unknown Source) at java.SocketInputStream.read(Unknown Source) at sun.security.ssl.InputRecord.readFully(Unknown Source) at sun.security.ssl.InputRecord.read(Unknown Source) at sun.security.ssl.SSLSocketImpl.readRecord(Unknown Source) at sun.security.ssl.SSLSocketImpl.performInitialHandshake(Unknown Source) at sun.security.ssl.SSLSocketImpl.writeRecord(Unknown Source) at sun.security.ssl.AppOutputStream.write(Unknown Source) at java.io.BufferedOutputStream.flushBuffer(Unknown Source) at java.io.BufferedOutputStream.flush(Unknown Source) at java.io.DataOutputStream.flush(Unknown Source) at com.rabbitmq.client.impl.SocketFrameHandler.sendHeader(SocketFrameHandler.java:147) at com.rabbitmq.client.impl.SocketFrameHandler.sendHeader(SocketFrameHandler.java:153) at com.rabbitmq.client.impl.AMQConnection.start(AMQConnection.java:294) at com.rabbitmq.client.impl.recovery.RecoveryAwareAMQConnectionFactory.newConnection(RecoveryAwareAMQConnectionFactory.java:63) at com.rabbitmq.client.impl.recovery.AutorecoveringConnection.init(AutorecoveringConnection.java:99) at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:921) at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:880) at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:838) at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:990) at test.main(test.java:25)

    推荐答案

    我在这里遇到了同样的问题:RabbitMQ 连接重置异常.Windows 的解决方案是在rabbit 配置文件中为证书和密钥的路径添加反斜杠.

    I had the same issue right here: RabbitMQ Connection reset Exception. Solution for Windows was to add backslash in rabbit config file for paths to certs and key.

    更多推荐

    RabbitMQ 连接重置

    本文发布于:2023-11-24 12:31:25,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1625210.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:RabbitMQ

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!