Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RabbitMQ Connection reset

Tags:

java

rabbitmq

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)
like image 216
DoctorMckay Avatar asked May 28 '18 08:05

DoctorMckay


People also ask

Why is RabbitMQ connection closed?

A common cause for connections being abruptly closed as soon as they're started is a TCP load balancer's heartbeat. If this is the case you should see these messages at very regular intervals, and the generally accepted practice seems to be to ignore them.

How do I check my RabbitMQ connection?

Verify Server Configuration Here are the recommended steps: Make sure the node is running using rabbitmq-diagnostics status. Verify config file is correctly placed and has correct syntax/structure. Inspect listeners using rabbitmq-diagnostics listeners or the listeners section in rabbitmq-diagnostics status.

How do I establish a connection with RabbitMQ?

In order for a client to interact with RabbitMQ it must first open a connection. This process involves a number of steps: Application configures the client library it uses to use a certain connection endpoint (e.g. hostname and port) The library resolves the hostname to one or more IP addresses.

How many connections can RabbitMQ handle?

Below is the default TCP socket option configuration used by RabbitMQ: TCP connection backlog is limited to 128 connections.


1 Answers

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.

like image 134
DistantBlue Avatar answered Oct 09 '22 22:10

DistantBlue