Reputation: 87
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.
Upvotes: 3
Views: 1954
Reputation: 471
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();
Upvotes: 0
Reputation: 156
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.
Upvotes: 4