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,214
  • 5
  • 18
  • 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

7 Answers7

10

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

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
  • 30,962
  • 25
  • 85
  • 135
error505
  • 1,126
  • 1
  • 17
  • 29
  • I tried all the options, including setting the hostname in the code mentioned in the docker file, 127.0.0.1 and localhost but none of them worked. After setting the IP address of the machine it started working. – Nilesh Thakkar Apr 26 '23 at 20:27
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,068
  • 1
  • 18
  • 32
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
  • 9,014
  • 5
  • 45
  • 57
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,897
  • 2
  • 19
  • 26
0

I restarted powershell and again wrote from the RabbitMQ documentation "docker run -it --rm --name rabbitmq -p 5672:5672 -p 15672:15672 rabbitmq:3.12-management"

From the documentation at https://www.rabbitmq.com/download.html

and earned. I'm sure it just needs to be fully configured so that it doesn't do this every time

  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Aug 17 '23 at 04:41