3

I got this exception while I was trying to connect to rabbitmq. My app is running on .NET 5. i dont use private vpc i have set the mq to public

Exception: None of the specified endpoints were reachable

Then I debugged the code and found that

Unable to write data to the transport connection: An existing connection was forcibly closed by the remote host..

It tries to connect from my local machine. I was running rabbit mq locally and it was working fine but when moved to aws I got this exception.

Here are my settings for connecting to rabbitmq service

"Connections": {
  "Default": {
    "HostName": "myserver.amazonaws.com",
    "UserName": "username",
    "Password": "password",
    "Port": 5671
  }
}

i use event bus that attached with framework that i use to develop my project it is called abp framework here is my code to configure connection

Configure<BaseRabbitMqOptions>(options =>
        {
            options.Connections.Default.HostName = configuration["RabbitMQ:Connections:Default:HostName"];
            options.Connections.Default.UserName = configuration["RabbitMQ:Connections:Default:UserName"];
            options.Connections.Default.Password = configuration["RabbitMQ:Connections:Default:Password"];
            options.Connections.Default.Port = configuration.GetValue<int>("RabbitMQ:Connections:Default:Port");
            options.Connections.Default.AmqpUriSslProtocols = System.Security.Authentication.SslProtocols.Tls12;
            
            options.Connections.Default.VirtualHost = "/";
        }
       );

Update i have set my connection to use ssl and now i get this exeption

AuthenticationException: The remote certificate was rejected by the provided RemoteCertificateValidationCallback.
7
  • Please also show the code that sets up the connection as well; whether you're using EasynetQ or Mass Transit. Also; we'll need to know whether your VPC is configured to allow you to have IP access to that box. If you're running RabbitMQ on EC2, your VPC has to be configured to allow your local machine's IP access to that box. To "Whitelist" it. Commented Jul 7, 2021 at 20:32
  • @GeorgeStocker i configured vpc to be public i edited the question , i use abp framwork and it has event bus attached with it not masstransit or easynetQ Commented Jul 8, 2021 at 0:45
  • none of the code you wrote shows the connection being opened. Can you connect to the rabbitmq management UI if you remote into the server? Commented Jul 8, 2021 at 1:56
  • the framework abstract the connection being established , i just give it the configs, yes i can connect to rabbitmq management ui , i enabled ssl and now it gives me this exception AuthenticationException: The remote certificate was rejected by the provided RemoteCertificateValidationCallback. @GeorgeStocker Commented Jul 8, 2021 at 2:03
  • 1
    i'm not using EC2 , instead i use amazon mq service , i have discovered the problem , when i enable ssl i should pass the server name that contains ssl certificate in my situation it was the same host name of the rabbitmq server , thanks for your help @GeorgeStocker Commented Jul 8, 2021 at 13:50

2 Answers 2

4

I had the same problem and solved by specifying the server hostname in the SslOption.ServerName property like this:

var factory = new ConnectionFactory
{
    UserName = userName,
    Password = password,
    VirtualHost = virtualHost,
    HostName = hostname,
    Port = port,
    Ssl = new SslOption
    {
        Enabled = useSsl,
        ServerName = hostname
    }
};

The solution is based on the comment here by OP, I just wanted to add it as an answer for posterity.

Sign up to request clarification or add additional context in comments.

Comments

0

This worked for me. In case anyone also have this problem.

var factory = new ConnectionFactory {
  UserName = "user",
  Password = "password",
};

factory.Ssl.Enabled = true;
factory.Port = 5671;
factory.Uri = new Uri("amqps://yourguid.mq.eu-west-1.amazonaws.com");

using var connection = factory.CreateConnection();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.