RabbitMQ 连接重置 [英] RabbitMQ Connection reset

查看:102
本文介绍了RabbitMQ 连接重置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 java 代码将一个简单的 RabbitMQ 连接到我的服务器(正在执行 RabbitMQ 服务).执行以下代码(source here)给了我 java.net.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.net.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:

  1. 验证服务器是否打开了我要连接的端口.
  2. 验证客户端不会阻止我与防火墙等的连接.
  3. 在 RabbitMQ 上创建一个新的虚拟主机并为其授予权限.
  4. 验证 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 http://www.rabbitmq.com/ssl.html#validating-cerficates to learn more about peer certificate validation.
Exception in thread "main" java.net.SocketException: Connection reset
 at java.net.SocketInputStream.read(Unknown Source)
 at java.net.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 连接重置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆