12

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.

jkyadav
  • 1,174
  • 5
  • 17
  • 32
  • 1
    How stable is your network? – Yuval Itzchakov Jul 15 '15 at 05:43
  • @YuvalItzchakov that is AWS server and it seems up all the time. – jkyadav Jul 15 '15 at 05:45
  • I-m having the same issue. There have been things like Skype affecting RabbitMQ, not sure why. Also sometimes I have to stop RabbitMQ service, wait a bit and start it again (if I restart it it does not work) It's really annoying not knowing what the problem is! – diegosasw Feb 24 '17 at 09:50

6 Answers6

8

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
                }
        };
3

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);
Peyman
  • 3,000
  • 1
  • 16
  • 30
3

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.

saille
  • 8,727
  • 4
  • 43
  • 56
3

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.

Dharman
  • 26,923
  • 21
  • 73
  • 125
error505
  • 1,086
  • 1
  • 15
  • 28
1

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.

0

The important thing here is: which OS uses the client? Is it running Windows XP/7?

It might had reached the limit of concurrent TCP connections.

Here is a link about how to increase that limit on Windows 7.

I had same issue when made a stress testing with .NET RabbitMQ Client running Win7.

flam3
  • 1,669
  • 1
  • 16
  • 25