title: RabbitMQ Connection refused 127.0.0.1:5672
body: <p>I am preparing a simple ASP.NET Core MVC web application.</p>
  <p>I have installed RabbitMQ server to my laptop. RabbitMQ Management UI is running on <code>localhost:15672</code>.</p>
  <p>Rabbit MQ cluster name is like: <code>rabbit@CR00001.ABC.COM.LOCAL</code></p>
  <p>I am trying to send message to rabbitmq in controller. But I am getting <strong>None of the specified endpoints were reachable</strong> error.</p>
  <p>If I use 'localhost' as host name, I get <strong>Connection refused 127.0.0.1:5672</strong> in inner exceptions.</p>
  <p>If I use <code>rabbit</code> as host name, I get <strong>Name or service not known</strong></p>
  <p>I've tried to solve the problem according to other StackOverflow questions, however, none of them could solved my problem.</p>
  <p><strong>Home controller:</strong></p>
  <pre><code>        [HttpPost]
          public void SendMessage([FromBody]Message message)
          {
              try
              {
                  var factory = new ConnectionFactory()
                  {
                      UserName = _username,
                      Password = _password,
                      HostName = _hostname,
                      VirtualHost = &quot;/&quot;,
                      Port = _port,
                  };
                  using (var connection = factory.CreateConnection())
                  using (var channel = connection.CreateModel())
                  {
                      channel.QueueDeclare(queue: _queueName,
                                           durable: false,
                                           exclusive: false,
                                           autoDelete: false,
                                           arguments: null);
  
                      var body = Encoding.UTF8.GetBytes(message.Text);
  
                      channel.BasicPublish(exchange: &quot;&quot;,
                                           routingKey: _queueName,
                                           basicProperties: null,
                                           body: body);
                  }
  
              }
              catch (Exception ex)
              {
  
              }
          }
  </code></pre>
  <p><strong>appsettings.json</strong></p>
  <pre><code>{
    &quot;Logging&quot;: {
      &quot;LogLevel&quot;: {
        &quot;Default&quot;: &quot;Information&quot;,
        &quot;Microsoft&quot;: &quot;Warning&quot;,
        &quot;Microsoft.Hosting.Lifetime&quot;: &quot;Information&quot;
      }
    },
    &quot;AllowedHosts&quot;: &quot;*&quot;,
    &quot;RabbitMq&quot;: {
      &quot;Hostname&quot;: &quot;localhost&quot;,
      &quot;QueueName&quot;: &quot;WordQueue&quot;,
      &quot;UserName&quot;: &quot;test&quot;,
      &quot;Password&quot;: &quot;test&quot;,
      &quot;Port&quot;: 5672
    }
  }
  </code></pre>
  <p>Here is test user configuration in Rabbit MQ Management UI
  <a href="https://i.stack.imgur.com/TTKIb.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/TTKIb.png" alt="test user configuration" /></a></p>