简体   繁体   English

与容器上RabbitMQ的连接问题

[英]Problem with connection to RabbitMQ on container

UPDATE: As it turns out, the port that rabbitmq uses is not 15672. I changed the port number from 15672 to 5672 in ConnectionFactory block and connected successfully. 更新:事实证明,rabbitmq使用的端口不是15672。我在ConnectionFactory块中将端口号从15672更改为5672并成功连接。

I've been trying to design a simple microservices architecture for trying and learning docker & rabbitmq. 我一直在尝试设计一个简单的微服务架构,以尝试和学习docker&rabbitmq。 So I've written these docker-compose.yml file as seen below: 所以我写了这些docker-compose.yml文件,如下所示:

version: '3.4'

networks:
 customqueue:

services:
  feed.api:
    image: feed.api:${TAG:-latest}
    build:
      context: .
      dockerfile: src/Services/Feed/Feed.Api/Dockerfile
    depends_on:
     - sqldata
     - rabbitmq
    ports:
     - "8000:80"
    networks:
     - customqueue

  like.api:
    image: like.api:${TAG:-latest}
    build:
      context: .
      dockerfile: src/Services/Like/Like.Api/Dockerfile
    depends_on:
     - rabbitmq
    ports:
     - "7000:70"
    networks:
     - customqueue

  rabbitmq:
    image: rabbitmq:3-management-alpine
    environment:
      RABBITMQ_DEFAULT_USER: "admin"
      RABBITMQ_DEFAULT_PASS: "password"
    ports:
      - "15672:15672"
      - "5672:5672" 
    networks:
     - customqueue 

feed.api is designed to be a subscriber, like.api is designed to be a publisher. feed.api被设计为订阅者, like.api被设计为发布者。 However, when i'm trying to run .net core code of feed.api, i'm getting this "None of the endpoints were reachable" error with RabbitMQ. 但是,当我尝试运行feed.api的.net核心代码时,RabbitMQ出现此“没有端点可达”错误。 RabbitMQ on container works fine. 容器上的RabbitMQ正常工作。 I'm trying to define a ConnectionFactory as below on Startup.cs in Feed.Api project. 我正在尝试在Feed.Api项目的Startup.cs上定义如下的ConnectionFactory。

var factory = new ConnectionFactory()
{
    HostName = "rabbitmq",
    UserName = "admin",
    Password = "password",
    Port = 15672,
    Protocol = Protocols.DefaultProtocol,
    RequestedConnectionTimeout = 2000,
    VirtualHost = "/",
};

Note: 注意:

  • "admin" user is administrator. “管理员”用户是管理员。

  • rabbitmq-management plugin is enabled. rabbitmq-management插件已启用。

EDIT:rabbimq:3-managament-alpine is appearently is an old image. 编辑:rabbimq:3-managament-alpine显然是一张旧照片。 Updating this to latest version might help, but i'm not sure. 将其更新为最新版本可能会有所帮助,但我不确定。 Has anyone have an idea about it? 有人对此有想法吗?

add a links: section to the rabbitmq container from the apis, otherwise they have no idea about the "rabbitmq" hostname. 在api上添加一个links:部分到Rabbitmq容器,否则它们对“ rabbitmq”主机名一无所知。

Links are getting deprecated in docker commands, but not in docker-compose . 链接在docker命令中被弃用,但在docker-compose中不被使用。

  feed.api:
    image: feed.api:${TAG:-latest}
    build:
      context: .
      dockerfile: src/Services/Feed/Feed.Api/Dockerfile
    depends_on:
     - sqldata
     - rabbitmq
    links:
     - rabbitmq
    ports:
     - "8000:80"
    networks:
     - customqueue

  like.api:
    image: like.api:${TAG:-latest}
    build:
      context: .
      dockerfile: src/Services/Like/Like.Api/Dockerfile
    depends_on:
     - rabbitmq
    ports:
     - "7000:70"
    links:
     - rabbitmq
    networks:
     - customqueue

  rabbitmq:
    image: rabbitmq:3-management-alpine
    environment:
      RABBITMQ_DEFAULT_USER: "admin"
      RABBITMQ_DEFAULT_PASS: "password"
    ports:
      - "15672:15672"
      - "5672:5672" 
    networks:
     - customqueue 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM