RabbitMQ Connection reset

吃可爱长大的小学妹 提交于 2020-05-26 02:30:07

问题


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. Verifying the server has the port I'm connecting to opened.
  2. Verifying the client does not block my connection with firewalls, etc.
  3. Creating a new Virtual Host on RabbitMQ and giving permissions to it.
  4. Verifying iptables is not blocking me at the server side.

Nothing seems to work, any ideas?

Full stacktrace here:

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)

回答1:


I don't know if this applies to your situation, but I recently resolved a similar situation while testing RabbitMQ 3.8.3, and the cause was that the key I was referencing was password-protected, but I had failed to provide the password in the RabbitMQ config, like this:

ssl_options.password = password

Unfortunately there was absolutely nothing in the RabbitMQ logs about this, even with the log level set to debug. When testing via various clients, a connection was established, but RabbitMQ immediately sent a connection reset.




回答2:


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.



来源:https://stackoverflow.com/questions/50562203/rabbitmq-connection-reset

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!