运行docker-compose up命令时RabbitMQ客户端抛出错误 [英] RabbitMQ client throwing error while running docker-compose up command

查看:212
本文介绍了运行docker-compose up命令时RabbitMQ客户端抛出错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用两个依赖于RabbitMQ的.net核心控制台应用程序运行docker-compose,我将Docker与Windows一起使用.

I am trying to run docker-compose with two .net core console applications having dependency of rabbitMQ, I am using Docker with Windows.

我已添加到控制台应用程序,如RabbitMQ官方文档 https:中所述://www.rabbitmq.com/tutorials/tutorial-one-dotnet.html

I have added to console application, as described on RabbitMQ official docs https://www.rabbitmq.com/tutorials/tutorial-one-dotnet.html

在这两个应用程序之外,我还添加了docker-compose.yml

Outside of both applications I have added docker-compose.yml

文件夹结构:

  1. Send.cs(与RabbitMQ文档中的一样)
  2. Send.csproj
  3. Dockerfile

  1. Send.cs (as it is in RabbitMQ docs)
  2. Send.csproj
  3. Dockerfile

FROM mcr.microsoft.com/dotnet/core/sdk:2.2 as build-env
WORKDIR /app

# Copy the project file and restore the dependencies
COPY *.csproj ./
RUN dotnet restore

# Copy the remaining source files and build the application
COPY . ./
RUN dotnet publish -c Release -o out

# Build the runtime image
FROM mcr.microsoft.com/dotnet/core/sdk:2.2
WORKDIR /app
COPY --from=build-env /app/out .
ENTRYPOINT ["dotnet", "Send.dll"]

2.接收

  1. Recieve.cs(与RabbitMQ文档中的一样)

  1. Recieve.cs (as it is in RabbitMQ docs)

Recieve.csproj

Recieve.csproj

Dockerfile(与发件人Dockerfile相同,只不过Send替换为Recieve)

Dockerfile (Same as Sender Dockerfile except Send replaced with Recieve)

3.Docker-compose.yml

  version: '3'

    services:
      rabbitmq:
        image: rabbitmq:3-management
        ports:
          - "5672:5672"
          - "15672:15672"
        container_name: rabbitmq
        hostname: my-rabbit
      Send:
        image: sender
        build:
          context: ./Send
          dockerfile: Dockerfile
        depends_on:
            - rabbitmq
      Reciever:
        image: reciever
        build:
          context: ./Recieve
          dockerfile: Dockerfile
        depends_on:
            - rabbitmq

引发错误

未处理的异常:RabbitMQ.Client.Exceptions.BrokerUnreachableException:无指定的端点可以访问---> System.AggregateException:一个或更多错误发生.(连接失败)--->RabbitMQ.Client.Exceptions.ConnectFailureException:连接失败---> System.Net.Internals.SocketExceptionFactory + ExtendedSocketException:连接被拒绝127.0.0.1:5672

Unhandled Exception: RabbitMQ.Client.Exceptions.BrokerUnreachableException: None of the specified endpoints were reachable ---> System.AggregateException: One or more errors occurred. (Connection failed) ---> RabbitMQ.Client.Exceptions.ConnectFailureException: Connection failed ---> System.Net.Internals.SocketExceptionFactory+ExtendedSocketException: Connection refused 127.0.0.1:5672

推荐答案

维克多的回答也很有帮助,但是问题是rabbitmq稍后启动,而发送和接收器之前启动.

Victor's answer was also helpful but, problem was the rabbitmq starting later, while send and receiver started before.

虽然我重新启动了相同的已停止的发送方和接收方容器,但是它按预期方式工作(因为rabbitmq容器已启动).因此,我在此处找到了有关容器的重试策略.

While I restarted the same stopped sender and receiver container, it was working as expected(because the rabbitmq container was up). So I have added the retry policies on container, found from here.

我的docker-compose文件的最终版本如下所示,并且工作正常.版本:"3"服务:

The final version of my docker-compose file is looking like below, and is working fine. version: '3' services:

  rabbitmq:
    image: rabbitmq:3-management
    ports:
      - "5672:5672"
      - "15672:15672"
    container_name: rabbitmq
    hostname: my-rabbit
    networks:
      - my-network-name
    healthcheck:
        test: ["CMD", "curl", "-f", "http://localhost:15672"]
        interval: 30s
        timeout: 10s
        retries: 5

  Send:
    image: sender
    build:
      context: ./Send
      dockerfile: Dockerfile
    depends_on:
        - rabbitmq
    restart: on-failure
    networks:
      - my-network-name
    links: 
        - rabbitmq

  Reciever:
    image: reciever
    build:
      context: ./Recieve
      dockerfile: Dockerfile
    depends_on:
        - rabbitmq
    restart: on-failure
    networks:
      - my-network-name
    links: 
        - rabbitmq
networks:
  my-network-name:
    driver: bridge

这篇关于运行docker-compose up命令时RabbitMQ客户端抛出错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆