RabbitMQ Docker Compose指定的端点都不可访问

a11xaf1n  于 2022-11-08  发布在  RabbitMQ
关注(0)|答案(3)|浏览(219)

我知道这看起来是重复的,但是我检查了所有其他的问题,没有一个解决了我的问题。

这是我的docker-compose yml文件:

version: '3.8'

services:
  #db:
   # image: postgres

  messageBroker:
    image: rabbitmq:management
    hostname: "messageBroker"
    healthcheck:
      test: rabbitmq-diagnostics -q ping
      interval: 5s
      timeout: 15s
      retries: 3
    networks:
      - services-network
    ports:
      - "15672:15672"
      - "5672:5672"
    environment:
      RABBITMQ_DEFAULT_USER: "admin"
      RABBITMQ_DEFAULT_PASS: "password"

  serviceDiscovery:
    image: steeltoeoss/eureka-server
    hostname: eureka-server
    networks:
      - services-network
    ports:
      - "8761:8761"

  order-api:
    image: ${DOCKER_REGISTRY-}orderapi
    hostname: orderapi
    environment:
      - Eureka__Client__ServiceUrl=http://serviceDiscovery:8761/eureka/
      - Eureka__Client__ShouldRegisterWithEureka=true
      - Eureka__Client__ValidateCertificates=false
    networks:
      - services-network
    depends_on:
      - serviceDiscovery
    build:
      context: .
      dockerfile: Services/Order/Dockerfile
    links:
      - "serviceDiscovery"

  product-api:
    image: ${DOCKER_REGISTRY-}productapi
    hostname: productapi
    restart: on-failure
    environment:
      - Eureka__Client__ServiceUrl=http://serviceDiscovery:8761/eureka/
      - Eureka__Client__ShouldRegisterWithEureka=true
      - Eureka__Client__ValidateCertificates=false
    networks:
      - services-network
    depends_on:
      messageBroker:
        condition: service_healthy
      serviceDiscovery:
        condition: service_started
    build:
      context: .
      dockerfile: Services/Products/Dockerfile
    links:
      - "serviceDiscovery"
      - "messageBroker"

networks:
  services-network:

这是我连接到RabbitMq的配置文件:

using RabbitMQ.Client;

namespace MessageBroker;

public static class MessageBrokerConfig
{
    public static IModel ChannelConfig()
    {
        var channel = new ConnectionFactory { Uri = new Uri("amqp://admin:password@messageBroker:5672") }
            .CreateConnection()
            .CreateModel();
        return channel;
    } 
}

但当我运行docker-compose时,仍然出现错误:

product-api_1       | Unhandled exception. RabbitMQ.Client.Exceptions.BrokerUnreachableException: None of the specified endpoints were reachable
product-api_1       |  ---> System.AggregateException: One or more errors occurred. (Connection failed)
product-api_1       |  ---> RabbitMQ.Client.Exceptions.ConnectFailureException: Connection failed
product-api_1       |  ---> System.Net.Sockets.SocketException (111): Connection refused

产品服务可以在服务发现中注册,没有任何问题,我遵循了几乎相同的步骤。我知道问题不在于rabbitmq容器需要时间来准备好,因为我可以在我的机器上连接。每次产品服务启动失败,它都会重新启动,但无论花费多少时间,我仍然得到这个错误。messageBroker容器的日志显示它是健康的(如果不是,我将无法通过我的机器访问).我没有任何其他的想法,我对这个问题3天alredy和我要疯了.我检查了教程,按照步骤去做却什么都没有。

xzv2uavs

xzv2uavs1#

解决了,伙计们!配置是正确的。但是,每当我创建一个新容器时,它都不会构建。因此,即使我更改了代码,它仍然具有第一个版本代码的映像。所以我做的唯一的事情就是删除服务的映像,Docker用正确的代码创建了一个新的映像。我认为这显然是一个临时的解决方案,因为它每次运行时都要构建/创建一个新的容器。但这是另一个主题,我认为它不会很难实现。也许用docker compose中的argx 1 m0n1x就足够了。但我只会在后面给予这个问题。

jk9hmnmh

jk9hmnmh2#

你的docker-compose文件没有正确的网络设置。我想你不需要链接。这里是一个最小的docker-compose,为我工作。我删除了链接,我删除了服务发现,这是不是在这里发挥作用的连接rabbitClient和代理。

version: '3.8'

services:
  #db:
   # image: postgres

  messageBroker:
    image: rabbitmq:management
    hostname: "messageBroker"
    healthcheck:
      test: rabbitmq-diagnostics -q ping
      interval: 5s
      timeout: 15s
      retries: 3
    networks:
      - services-network
    ports:
      - "15672:15672"
      - "5672:5672"
    environment:
      RABBITMQ_DEFAULT_USER: "admin"
      RABBITMQ_DEFAULT_PASS: "password"

  product-api:
    image: ${DOCKER-REGISTRY-}productapi
    hostname: productapi
    restart: on-failure
    environment:
      - Eureka__Client__ServiceUrl=http://serviceDiscovery:8761/eureka/
      - Eureka__Client__ShouldRegisterWithEureka=true
      - Eureka__Client__ValidateCertificates=false
    networks:
      - services-network
    depends_on:
      messageBroker:
        condition: service_healthy
    build:
      context: client
      dockerfile: Dockerfile

networks:
  services-network:
eagi6jfj

eagi6jfj3#

在docker-compose上,在网络中缺少了一些东西,把它这样写:

networks:
    services-network:
        driver: bridge

相关问题