My rabbitmq application is running on windows 2012 server, randomly I use to get this error.
Exception Type: RabbitMQ.Client.Exceptions.BrokerUnreachableException
None of the specified endpoints were reachable
at RabbitMQ.Client.ConnectionFactory.CreateConnection()
at Program.Main(String[] args)
Stream does not support writing.
at System.IO.BufferedStream.EnsureCanWrite()
at System.IO.BufferedStream.Write(Byte[] array, Int32 offset, Int32 count)
at RabbitMQ.Client.Impl.SocketFrameHandler.SendHeader()
at RabbitMQ.Client.Framing.Impl.Connection.StartAndTune()
at RabbitMQ.Client.Framing.Impl.Connection.Open(Boolean insist)
at RabbitMQ.Client.Framing.Impl.Connection..ctor(IConnectionFactory factory, Boolean insist, IFrameHandler frameHandler)
at RabbitMQ.Client.Framing.Impl.ProtocolBase.CreateConnection(IConnectionFactory factory, Boolean insist, IFrameHandler frameHandler)
at RabbitMQ.Client.ConnectionFactory.CreateConnection()
What could be the reason of failing the connection randomly, and automatically it starts connecting.
Can anyone help me out in this.
I had this problem, and finally I could solve it by adding the "Ssl" property of the ConnectionFactory class, with the "ServerName" sub-property specified.
Here is what I did, and it connected to the Rabbit MQ server. Please pay attention to the "ServerName" part of the code below:
var rabbitMqConnectionFactory
= new ConnectionFactory
{
HostName = rabbitMqHostName,
Port = rabbitMqPort,
UserName = rabbitMqUserName,
Password = rabbitMqPassword,
VirtualHost = rabbitMqVirtualHost,
RequestedHeartbeat = 60,
Ssl =
{
**ServerName** = rabbitMqHostName,
Enabled = useSsl
}
};
I have had the same problem and I solved it by creating new RabbitMQ Docker Container with docker compose:
rabbitmq:
container_name: rabbitmq
tty: true
hostname: rabbitmq
ports:
- "15672:15672"
- "5672:5672"
image: rabbitmq:3-management
environment:
- RABBITMQ_DEFAULT_USER=user
- RABBITMQ_DEFAULT_PASS=password
And to access it with trough the code I had to set in my appsettings.json file the host as the my localhost IP Address:
"RabbitMqSend": {
"Hostname": "192.168.0.12",
"QueueName": "SendQueue",
"UserName": "user",
"Password": "password"},
With this it worked for me.
It's hard to say whats the exactly problem, but one of the reason that cause to occur such issue is RabbitMQ heart beat, you can change this value. for more information you can check this linke Detecting Dead TCP Connections with Heartbeats
ConnectionFactory cf = new ConnectionFactory();
// set the heartbeat timeout to 60 seconds
cf.setRequestedHeartbeat(60);
There seem to be several situations in which you can get the "None of the specified endpoints were reachable" error.
I have seen this both when the RabbitMQ Service is not running, or the RabbitMQ Service is running but in an error state, and also when the client cannot connect e.g. the user does not have access to the Virtual Host that it is trying to connect to.
I had the same problem. In my case the port 5672 was closed. For find what was the problem I activate InnerException in my code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With