title: how to solve this error: RabbitMQ.Client.Exceptions.BrokerUnreachableException: 'None of the specified endpoints were reachable'
body: <p>i'm working in eshop order basket project. i want help for solving rabbitmq error from this code:</p>
  
  <pre><code>using Microsoft.Extensions.Logging; 
  using Polly; 
  using Polly.Retry; 
  using RabbitMQ.Client; 
  using RabbitMQ.Client.Events; 
  using RabbitMQ.Client.Exceptions; 
  using System; 
  using System.IO; 
  using System.Net.Sockets; 
  
  namespace InfiniteWorx.MRU.BuildingBlocks.EventBusRabbitMQ 
  { 
      public class DefaultRabbitMQPersistentConnection 
         : IRabbitMQPersistentConnection 
      { 
          private readonly IConnectionFactory _connectionFactory;  
          private readonly ILogger&lt;DefaultRabbitMQPersistentConnection&gt; _logger; 
          private readonly int _retryCount; 
          IConnection _connection; 
          bool _disposed; 
          object sync_root = new object(); 
          public DefaultRabbitMQPersistentConnection(IConnectionFactory 
  connectionFactory, ILogger&lt;DefaultRabbitMQPersistentConnection&gt; logger, int 
  retryCount = 5) 
          { 
              _connectionFactory = connectionFactory ?? throw new 
  ArgumentNullException(nameof(connectionFactory)); 
              _logger = logger ?? throw new 
  ArgumentNullException(nameof(logger)); 
              _retryCount = retryCount; 
          } 
          public bool IsConnected 
          { 
              get 
              { 
                  return _connection != null &amp;&amp; _connection.IsOpen &amp;&amp; 
  !_disposed; 
              } 
          } 
          public IModel CreateModel() 
          { 
              if (!IsConnected) 
              { 
                  throw new InvalidOperationException("No RabbitMQ connections 
  are available to perform this action"); 
              } 
  
              return _connection.CreateModel(); 
          } 
  
          public void Dispose() 
          { 
              if (_disposed) return; 
  
              _disposed = true; 
  
              try 
              { 
                  _connection.Dispose(); 
  
              } 
              catch (IOException ex) 
              { 
                  _logger.LogCritical(ex.ToString()); 
              } 
          } 
  
          public bool TryConnect() 
          { 
              _logger.LogInformation("RabbitMQ Client is trying to connect"); 
  
              lock (sync_root) 
              { 
                  var policy = RetryPolicy.Handle&lt;SocketException&gt;() 
                      .Or&lt;BrokerUnreachableException&gt;() 
                      .WaitAndRetry(_retryCount, retryAttempt =&gt; 
  TimeSpan.FromSeconds(Math.Pow(2, retryAttempt)), (ex, time) =&gt; 
                      { 
                          _logger.LogWarning(ex.ToString()); 
                      } 
                  ); 
  
                  policy.Execute(() =&gt; 
                  { 
                      _connection = _connectionFactory 
                            .CreateConnection(); 
                  }); 
  
                  if (IsConnected) 
                  { 
                      _connection.ConnectionShutdown += OnConnectionShutdown; 
                      _connection.CallbackException += OnCallbackException; 
                      _connection.ConnectionBlocked += OnConnectionBlocked; 
  
                      _logger.LogInformation($"RabbitMQ persistent connection 
  acquired a connection {_connection.Endpoint.HostName} and is subscribed to 
  failure events"); 
  
                      return true; 
                  } 
                  else 
                  { 
                      _logger.LogCritical("FATAL ERROR: RabbitMQ connections 
  could not be created and opened"); 
  
                      return false; 
                  } 
              } 
          } 
  
          private void OnConnectionBlocked(object sender, 
  ConnectionBlockedEventArgs e) 
          { 
              if (_disposed) return; 
  
              _logger.LogWarning("A RabbitMQ connection is shutdown. Trying to 
  re-connect..."); 
  
              TryConnect(); 
          } 
  
          void OnCallbackException(object sender, CallbackExceptionEventArgs e) 
          { 
              if (_disposed) return; 
  
              _logger.LogWarning("A RabbitMQ connection throw exception. 
  Trying to re-connect..."); 
  
              TryConnect(); 
          } 
  
          void OnConnectionShutdown(object sender, ShutdownEventArgs reason) 
          { 
              if (_disposed) return; 
  
              _logger.LogWarning("A RabbitMQ connection is on shutdown. Trying to re-connect..."); 
  
              TryConnect(); 
          } 
      } 
  } 
  </code></pre>
  
  <p>This is eroor msg when running the code:</p>
  
  <p>RabbitMQ.Client.Exceptions.BrokerUnreachableException: 'None of the specified endpoints were reachable'</p>
  
  <p>ArgumentNullException: Value cannot be null.
  ConnectFailureException: Connection failed</p>