title: RabbitMq DotNetCore Console App RabbitMQ.Client.Exceptions.BrokerUnreachableException: None of the specified endpoints were reachable
body: <p>I am running 3 projects with docker compose. These projects need rabbitmq and postgresql.</p>
  <p>-ReportAPI   (Produce data to RabbitMq) DotNetCoreWebAPI .Net Version -&gt; 6.0</p>
  <p>-Contact  DotNetCoreWebAPI .Net Version -&gt; 6.0</p>
  <p>-ReportConsumer (Consume data from RabbitMq) DotNetConsole App .Net Version -&gt; 6.0</p>
  <p><strong>Report.API Produce Data</strong></p>
  <pre class="lang-cs prettyprint-override"><code>var factory = new ConnectionFactory()
  {
      HostName = configuration.GetValue&lt;string&gt;(&quot;RabbitMq:Host&quot;),
      Password = configuration.GetValue&lt;string&gt;(&quot;RabbitMq:Password&quot;),
      UserName = configuration.GetValue&lt;string&gt;(&quot;RabbitMq:UserName&quot;),
      Port= configuration.GetValue&lt;int&gt;(&quot;RabbitMq:Port&quot;)
  
  };
  using (var connection = factory.CreateConnection())
  using (var channel = connection.CreateModel())
  {
      var body = Encoding.UTF8.GetBytes(Guid.NewGuid().ToString());
  
      var properties = channel.CreateBasicProperties();
      properties.Persistent = true;
      channel.QueueDeclare(queue: &quot;ReportQueue&quot;,
            durable: true,
            exclusive: false,
            autoDelete: false,
            arguments: null);
      channel.BasicPublish(exchange: &quot;&quot;,
                           routingKey: &quot;ReportQueue&quot;,
                           basicProperties: properties,
                           body: body );
  
  }
  </code></pre>
  <p>I can send data from Report Api Project to rabbitmq. There is no problem in the Report.API project, it works as I want and sends the data to the rabbit mq ReportQueue.</p>
  <p><strong>Report.API.appSettings.json</strong></p>
  <pre class="lang-json prettyprint-override"><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;ConnectionStrings&quot;: {
      &quot;ReportPostgreSql&quot;: &quot;User ID=postgres;Password=123456;Host=host.docker.internal;Port=5432;Database=Report;&quot;,
      &quot;ReportSqlServer&quot;: &quot;Server=.\\SQLSERVER;Database=Report;User Id=sa;Password=123456;&quot;
    },
    &quot;RabbitMq&quot;: {
      &quot;Host&quot;: &quot;host.docker.internal&quot;,
      &quot;UserName&quot;: &quot;guest&quot;,
      &quot;Password&quot;: &quot;guest&quot;,
      &quot;Port&quot;: 5672
    },
  }
  </code></pre>
  <p><strong>Report.API.Consumer</strong></p>
  <pre class="lang-cs prettyprint-override"><code> var factory = new ConnectionFactory()
              {
                  HostName = configuration.GetValue&lt;string&gt;(&quot;RabbitMq:Host&quot;),
                  Password = configuration.GetValue&lt;string&gt;(&quot;RabbitMq:Password&quot;),
                  UserName = configuration.GetValue&lt;string&gt;(&quot;RabbitMq:UserName&quot;),
                  Port = configuration.GetValue&lt;int&gt;(&quot;RabbitMq:Port&quot;)
  
              };
              Console.WriteLine(&quot;Connection&quot;);
  
              var connection = factory.CreateConnection();
              var channel = connection.CreateModel();
  
              Console.WriteLine(&quot;QueueDeclare&quot;);
              channel.QueueDeclare(queue: &quot;ReportQueue&quot;,
                  
                          durable: true,
                          exclusive: false,
                          autoDelete: false,
                          arguments: null);
              Console.WriteLine(&quot;QueueDeclare End&quot;);
  
  
              var consumer = new EventingBasicConsumer(channel);
              consumer.Received += (sender, eventArgs) =&gt;
              {
                  try
                  {
                      Console.WriteLine(&quot;Recieved Start&quot;);
                      var data = Encoding.UTF8.GetString(eventArgs.Body.ToArray());
  
                      Console.WriteLine(&quot;Data:&quot;+data);
  
                      Console.WriteLine(&quot;Recieved End&quot;);
                      channel.BasicAck(eventArgs.DeliveryTag, false);
  
                  }
                  catch (Exception ex)
                  {
                      Console.WriteLine(ex);
                      channel.BasicNack(eventArgs.DeliveryTag, false, true);
                  }
  
              };
              Console.WriteLine(&quot;BasicConsume Start&quot;);
  
              channel.BasicConsume(queue: &quot;ReportQueue&quot;, autoAck: false, consumer: consumer);
              Console.WriteLine(&quot;BasicConsume End&quot;);
              Console.In.Read() ;
  </code></pre>
  <p><strong>Report.Consumer.appSettings.json</strong></p>
  <pre class="lang-json prettyprint-override"><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;Services&quot;: {
      &quot;ReportServiceEndPoint&quot;: &quot;https://localhost:8201&quot;,
      &quot;ContactServiceEndPoint&quot;: &quot;https://localhost:7201&quot;
    },
    &quot;RabbitMq&quot;: {
      &quot;Host&quot;: &quot;rabbitmq&quot;,
      &quot;UserName&quot;: &quot;guest&quot;,
      &quot;Password&quot;: &quot;guest&quot;,
      &quot;Port&quot;: 5672
  
    }
  }
  
  </code></pre>
  <p><strong>docker-compose.yml</strong></p>
  <pre><code>version: '3.4'
  
  services:
    rabbitmq:
      # login guest:guest
      image: rabbitmq:3-management-alpine
      hostname: &quot;rabbitmq&quot;
      labels:
        NAME: &quot;rabbitmq&quot;
      ports:
        - 5672:5672
        - 15672:15672
      healthcheck:
        test: rabbitmq-diagnostics -q ping
        interval: 30s
        timeout: 10s
        retries: 5
    postgreserver:
      image: postgres
      restart: always
      environment:
        POSTGRES_PASSWORD: &quot;123456&quot;
        POSTGRES_USER: &quot;postgres&quot;
      ports:
        - 5432:5432
    contactapi:
      image: ${DOCKER_REGISTRY-}contactapi
      build:
        context: .
        dockerfile: Contact.API/Dockerfile
      environment:
        - ASPNETCORE_ENVIRONMENT=Development
        - ASPNETCORE_URLS=http://+:7200;http://+:7201
        - ASPNETCORE_Kestrel__Certificates__Default__Password=lolo1234lolo
        - ASPNETCORE_Kestrel__Certificates__Default__Path=/https/aspnetapp.pfx
      ports:
        - 7200:7200
        - 7201:7201
      volumes:
        - ~/.aspnet/https:/https:ro
      depends_on:
        - postgreserver
      links:
        - postgreserver
    reportapi:
      image: ${DOCKER_REGISTRY-}reportapi
      build:
        context: .
        dockerfile: Report.API/Dockerfile
      environment:
        - ASPNETCORE_ENVIRONMENT=Development
        - ASPNETCORE_URLS=http://+:8200;http://+:8201
        - ASPNETCORE_Kestrel__Certificates__Default__Password=lolo1234lolo
        - ASPNETCORE_Kestrel__Certificates__Default__Path=/https/aspnetapp.pfx
      ports:
        - 8200:8200
        - 8201:8201
      volumes:
        - ~/.aspnet/https:/https:ro
      depends_on:
        - postgreserver
        - rabbitmq
      links:
        - postgreserver
        - rabbitmq
    consumer:
      image: ${DOCKER_REGISTRY-}consumer
      restart: on-failure
      build:
        context: .
        dockerfile: Report.Consumer/Dockerfile
      depends_on:
        - contactapi
        - reportapi
        - rabbitmq
      links:
        - contactapi
        - reportapi
        - rabbitmq
  </code></pre>
  <p>when I run it it <code>docker compose up</code> fails because consume throw RabbitMQ.Client.Exceptions.BrokerUnreachableException: None of the specified endpoints were reachable</p>
  <p>I noticed it while experimenting. When I say docker compose up, rabbitmq, postgre Report.API and Contact.API are running. If I run the ReportConsumer project in a single container while the other 4 containers are working with compose, it works seamlessly with the containers in the other compose. But why doesn't it work with Compose? I've been researching the problem for 1.5 weeks and couldn't get any results.</p>
  <p><a href="https://i.stack.imgur.com/dHGjr.png" rel="nofollow noreferrer">Docker Compose Up Output</a></p>
  <p>Thanks for all your support and comments.</p>