title: RabbitMQ 'None of the Specified Endpoints were Reachable'
body: <p>Trying to create a connection to RabbitMQ inside a Virtual Machine. My specs are as follow:</p>
  <p>RabbitMQ-Host: Windows 10
  VirtualMachine: CentOS 7</p>
  <p>The rabbitMQ is succesfully installed in the host, the management web page is working perfectly nice and inside the host machine I can succesfully send and retrieve messages.
  Using a simple Python connection tester, I can don't receive any errors and the connections appears to be succesfull. Followed tutorial at: <a href="https://www.rabbitmq.com/tutorials/tutorial-one-python.html" rel="nofollow noreferrer">https://www.rabbitmq.com/tutorials/tutorial-one-python.html</a></p>
  <p>The problem is when I try to connect to RabbitMQ via the virtual machine.
  Follow all the common fixes:</p>
  <ul>
  <li>Port Access
  <ul>
  <li>All ports are open. Tried with firewall ON and OFF. curl -v telnet://HOSTNAME:5672 works as intendeed from the CentOS machine</li>
  <li>curl hostname:15672 returns the index page</li>
  </ul>
  </li>
  <li>Listeners
  <ul>
  <li>rabbitmq-diagnostics status returns OK of the node</li>
  <li>rabbitmq-diagnostics listeners shows my listener on the HOST</li>
  </ul>
  </li>
  <li>Diagnostics
  <ul>
  <li>executed &quot;rabbitmq-diagnostics environment&quot; and all seems fine</li>
  <li>RabbitMQ is not directing any logs from the connection in rabbit.log</li>
  </ul>
  </li>
  </ul>
  <p>Error:</p>
  <pre><code>None of the specified endpoints were reachable
     at RabbitMQ.Client.ConnectionFactory.CreateConnection(IEndpointResolver endpointResolver, String clientProvidedName)
     at RabbitMQ.Client.ConnectionFactory.CreateConnection(String clientProvidedName)
    at RabbitMQ.Client.ConnectionFactory.CreateConnection()
    at gennera.server.consumer.RabbitMqConsumer.CreateConnection() in /root/sap-api/Queue/AcademicQueue/gennera.server/consumer/RabbitMqConsumer.cs:line 46
  Connection failed
    at RabbitMQ.Client.Impl.SocketFrameHandler.ConnectOrFail(ITcpClient socket, AmqpTcpEndpoint endpoint, TimeSpan timeout)
    at RabbitMQ.Client.Impl.SocketFrameHandler.ConnectUsingAddressFamily(AmqpTcpEndpoint endpoint, Func`2 socketFactory, TimeSpan timeout, AddressFamily family)
    at RabbitMQ.Client.Impl.SocketFrameHandler.ConnectUsingIPv4(AmqpTcpEndpoint endpoint, Func`2 socketFactory, TimeSpan timeout)
    at RabbitMQ.Client.Impl.SocketFrameHandler..ctor(AmqpTcpEndpoint endpoint, Func`2 socketFactory, TimeSpan connectionTimeout, TimeSpan readTimeout, TimeSpan writeTimeout)
    at RabbitMQ.Client.Framing.Impl.IProtocolExtensions.CreateFrameHandler(IProtocol protocol, AmqpTcpEndpoint endpoint, Func`2 socketFactory, TimeSpan connectionTimeout, TimeSpan readTimeout, TimeSpan writeTimeout)
    at RabbitMQ.Client.ConnectionFactory.CreateFrameHandler(AmqpTcpEndpoint endpoint)
    at RabbitMQ.Client.EndpointResolverExtensions.SelectOne[T](IEndpointResolver resolver, Func`2 selector)
  Connection refused
    at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.ThrowException(SocketError error, CancellationToken cancellationToken)
    at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.System.Threading.Tasks.Sources.IValueTaskSource.GetResult(Int16 token)
    at System.Threading.Tasks.ValueTask.ValueTaskSourceAsTask.&lt;&gt;c.&lt;.cctor&gt;b__4_0(Object state)
  --- End of stack trace from previous location ---
    at RabbitMQ.Client.Impl.TcpClientAdapter.ConnectAsync(String host, Int32 port)
    at RabbitMQ.Client.Impl.TaskExtensions.TimeoutAfter(Task task, TimeSpan timeout)
    at RabbitMQ.Client.Impl.SocketFrameHandler.ConnectOrFail(ITcpClient socket, AmqpTcpEndpoint endpoint, TimeSpan timeout)
  Unhandled exception. System.Exception: None of the specified endpoints were reachable
    at gennera.server.consumer.RabbitMqConsumer.CreateConnection() in /root/sap-api/Queue/AcademicQueue/gennera.server/consumer/RabbitMqConsumer.cs:line 61
    at gennera.server.consumer.RabbitMqConsumer..ctor() in /root/sap-api/Queue/AcademicQueue/gennera.server/consumer/RabbitMqConsumer.cs:line 27
    at gennera.server.Worker.ExecuteAsync(CancellationToken stoppingToken) in /root/sap-api/Queue/AcademicQueue/gennera.server/Worker.cs:line 20
    at Microsoft.Extensions.Hosting.Internal.Host.StartAsync(CancellationToken cancellationToken)
    at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(IHost host, CancellationToken token)
    at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(IHost host, CancellationToken token)
    at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.Run(IHost host)
    at gennera.server.Program.Main(String[] args) in /root/sap-api/Queue/AcademicQueue/gennera.server/Program.cs:line 12 
  </code></pre>
  <p>C# code:</p>
  <pre><code>try
  {
      var connectionFactory = new ConnectionFactory
      {
          HostName = rabbitMqUrl,
          UserName = &quot;gennera&quot;,
          Password = &quot;gennera&quot;,
          Port = AmqpTcpEndpoint.UseDefaultPort,
          VirtualHost = &quot;/&quot;,
          RequestedHeartbeat = new TimeSpan(60),
          Ssl = { ServerName = rabbitMqUrl, Enabled = false }
      };
  
      return connectionFactory.CreateConnection();
  }
  catch(Exception e)
  {
      Console.WriteLine(Environment.GetEnvironmentVariable(&quot;rabbitMqUrl&quot;));
      var tempExcetion = e.InnerException;
      Console.WriteLine(e.Message);
      Console.WriteLine(e.StackTrace);
      while (tempExcetion.InnerException != null)
      {
          Console.WriteLine(tempExcetion.InnerException.Message);
          Console.WriteLine(tempExcetion.InnerException.StackTrace);
          tempExcetion = tempExcetion.InnerException;
      }
      // Console.WriteLine(e.StackTrace);
      throw new Exception(e.Message);
  }
  </code></pre>
  <p>Python Code:</p>
  <pre><code>#!/usr/bin/env python
  import pika
  credentials = pika.PlainCredentials('gennera', 'gennera')
  connection = pika.BlockingConnection(pika.ConnectionParameters(host='192.168.3.2',credentials=credentials))
  channel = connection.channel()
  print(connection)
  print(channel)
  </code></pre>
  <p>Python Result:</p>
  <pre><code>&lt;BlockingConnection impl=&lt;SelectConnection OPEN transport=&lt;pika.adapters.utils.io_services_utils._AsyncPlaintextTransport object at 0x7f55ddf9f1d0&gt; params=&lt;ConnectionParameters host=192.168.3.2 port=5672 virtual_host=/ ssl=False&gt;&gt;&gt;
  &lt;BlockingChannel impl=&lt;Channel number=1 OPEN conn=&lt;SelectConnection OPEN transport=&lt;pika.adapters.utils.io_services_utils._AsyncPlaintextTransport object at 0x7f55ddf9f1d0&gt; params=&lt;ConnectionParameters host=192.168.3.2 port=5672 virtual_host=/ ssl=False&gt;&gt;&gt;&gt;
  </code></pre>
  <p>Thanks in advance!</p>
  <p>------ EDIT ------</p>
  <p>Resolved it by changing the code in CreateConnection to:</p>
  <pre><code>try
  {
      var connectionFactory = new ConnectionFactory
      {
          Uri = new Uri($&quot;amqp://gennera:gennera@{rabbitMqUrl}/&quot;),
          DispatchConsumerAsync = false,
          ConsumerDispatchConcurrency = 1,
      };
  </code></pre>
  <p>The properties &quot;DispatchConsumerAsync&quot; and &quot;ConsumerDispatchConcurrency&quot; did the trick.</p>