在 docker-compose 下运行时,如何让 Dapr 服务到服务调用工作?

问题描述 投票:0回答:1

尝试使用 Dapr SDK 调用服务时收到以下错误。

System.Net.Http.HttpRequestException: Connection refused (127.0.0.1:3500)
 ---> System.Net.Sockets.SocketException (111): Connection refused

这是我尝试调用的服务的 docker-compose 设置:

 quest-service:
    image: ${DOCKER_REGISTRY-gamification}/quest-service:${TAG:-latest}
    environment:
      - ASPNETCORE_ENVIRONMENT=Development
      - ASPNETCORE_URLS=http://0.0.0.0:80
      - SeqServerUrl=http://seq
    build:
      context: .
      dockerfile: Services/LW.Gamification.QuestService/Dockerfile
    ports:
      - "5110:80"
      - "50010:50001"

  quest-service-dapr:
    image: "daprio/daprd:latest"
    command: ["./daprd",
      "-app-id", "Quest-Service",
      "-app-port", "80",
      "-components-path", "/Components",
      "-config", "/Configuration/config.yaml"
      ]
    volumes:
      - "./Dapr/Components/:/Components"
      - "./Dapr/Configuration/:/Configuration"
    depends_on:
      - quest-service
    network_mode: "service:quest-service"

以及来电者的设置:

player-service:
    image: ${DOCKER_REGISTRY-gamification}/player-service:${TAG:-latest}
    environment:
      - ASPNETCORE_ENVIRONMENT=Development
      - ASPNETCORE_URLS=http://0.0.0.0:80
      - SeqServerUrl=http://seq
    build:
      context: .
      dockerfile: Services/LW.Gamificaiton.PlayerService/Dockerfile
    ports:
      - "5109:80"
      - "50009:50001"

  player-service-dapr:
    image: "daprio/daprd:latest"
    command: ["./daprd",
      "-app-id", "Player-Service",
      "-app-port", "80",
      "-components-path", "/Components",
      "-config", "/Configuration/config.yaml"
      ]
    volumes:
      - "./Dapr/Components/:/Components"
      - "./Dapr/Configuration/:/Configuration"
    depends_on:
      - player-service
    network_mode: "service:player-service"

这是无法工作的代码:

            // demo service to service call
            var httpClient = DaprClient.CreateInvokeHttpClient("Quest-Service");
            var requestUri = $"api/v1/Quest";

            var result = await httpClient.GetFromJsonAsync<IEnumerable<string>>(requestUri);

注意:消息传递工作正常。 :-)

我是 Dapr 新手,所以我一定是做了一些愚蠢的错误,也许与端口有关..我只是不知道!

asp.net-core docker-compose dapr
1个回答
1
投票

从以下问题开始:Dapr Client Docker Compose Issue

我设法使用以下 docker-compose 配置使其部分正常工作:

services:
  placement:
    image: "daprio/dapr"
    command: ["./placement", "-port", "50000", "-log-level", "debug"]
    ports:
      - "50000:50000"

  quest-service:
    image: ${DOCKER_REGISTRY-gamification}/quest-service:${TAG:-latest}
    environment:
      - ASPNETCORE_ENVIRONMENT=Development
      - ASPNETCORE_URLS=http://0.0.0.0:80
      - SeqServerUrl=http://seq
      - DAPR_GRPC_PORT=50010
    build:
      context: .
      dockerfile: Services/LW.Gamification.QuestService/Dockerfile
    ports:
      - "5110:80"
      - "50010:50010"
    depends_on:
      - placement
      - rabbitmq
      - redis
      - seq
      - zipkin

  quest-service-dapr:
    image: "daprio/daprd:latest"
    command: ["./daprd",
      "-app-id", "Quest-Service",
      "-app-port", "80",
      "-placement-host-address", "placement:50000",
      "-dapr-grpc-port", "50010",
      "-components-path", "/Components",
      "-config", "/Configuration/config.yaml"
      ]
    volumes:
      - "./Dapr/Components/:/Components"
      - "./Dapr/Configuration/:/Configuration"
    depends_on:
      - quest-service
    network_mode: "service:quest-service"

  generatetraffic:
    image: ${DOCKER_REGISTRY-gamification}/generatetraffic:${TAG:-latest}
    environment:
      - ASPNETCORE_ENVIRONMENT=Development
      - ASPNETCORE_URLS=http://0.0.0.0:80
      - SeqServerUrl=http://seq
      - DAPR_GRPC_PORT=50017
    build:
      context: .
      dockerfile: Services/LW.Gamification.GenerateTraffic/Dockerfile
    ports:
      - "5117:80"
      - "50017:50017"
    depends_on:
      - placement
      - rabbitmq
      - redis
      - seq
      - zipkin
      
  generatetraffic-dapr:
    image: "daprio/daprd:latest"
    command: ["./daprd",
      "-app-id", "Generate-Traffic",
      "-app-port", "80",
      "-placement-host-address", "placement:50000",
      "-dapr-grpc-port", "50017",
      "-components-path", "/Components",
      "-config", "/Configuration/config.yaml"
      ]
    volumes:
      - "./Dapr/Components/:/Components"
      - "./Dapr/Configuration/:/Configuration"
    depends_on:
      - generatetraffic
    network_mode: "service:generatetraffic"



但是,我仍然遇到一些已记录的 API 无法正常工作的问题!

    var httpClient = DaprClient.CreateInvokeHttpClient("Quest-Service");
    var requestUri = $"api/v1/Quest";       
    var result = await httpClient.GetAsync(requestUri);

还是失败?

© www.soinside.com 2019 - 2024. All rights reserved.