'Exception while trying to connect rabbit mq on aws mq from .net core 5 application
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.
Solution 1:[1]
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.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | blazky |
