1

我在使用我的微服务启动和运行 Dapr 时遇到了重大问题。每次我尝试调用另一个服务时,它都会返回 500 错误消息

client error: the server closed connection before returning the first response byte. Make sure the server returns 'Connection: close' response header before closing the connection

服务和 dapr 边车目前在我们的开发机器上的 docker-compose 中运行,但在正确部署后将在 Kubernetes 中运行。

当我查看 Docker for Windows 中 dapr 容器的日志时,我可以看到在端口 443 上发现了应用程序以及一些初始化消息,但此后没有记录任何其他内容,即使我发出调用请求也是如此。

我有一个名为 clients 的容器,我在其中调用了一个名为 test 的 API,然后尝试在另一个名为 simpleapi 的容器中调用 Microsoft 的示例天气预报 API。

我正在使用 swaggerUI 来调用 api。测试 api 返回 200,但是当我在调用上放置断点时,我可以看到响应是 500。

如果我直接使用 swaggerui 调用 weatherforecast api,它会返回 200 和预期的有效负载。

我在容器中运行 Dapr 仪表板,它没有显示任何应用程序。

Docker-Compose.yml

version: '3.4'

services:
  clients:
    image: ${DOCKER_REGISTRY-}clients
    container_name: "Clients"
    build:
      context: .
      dockerfile: Clients/Dockerfile
    ports:
      - "50002:50002"
    depends_on:
     - placement
     - database
    networks:
      - platform
  
  clients-dapr:
    image: "daprio/daprd:edge"
    container_name: clients-dapr
    command: [
      "./daprd",
     "-app-id", "clients",
     "-app-port", "443",
     "-placement-host-address", "placement:50006",
     "-dapr-grpc-port", "50002"
     ]
    depends_on:
      - clients
    network_mode: "service:clients"

  simpleapi:
    image: ${DOCKER_REGISTRY-}simpleapi
    build:
      context: .
      dockerfile: SimpleAPI/Dockerfile
    ports:
      - "50003:50003"
    depends_on:
      - placement
    networks:
      - platform

  simpleapi-dapr:
    image: "daprio/daprd:edge"
    container_name: simpleapi-dapr
    command: [
      "./daprd",
     "-app-id", "simpleapi",
     "-app-port", "443",
     "-placement-host-address", "placement:50006",
     "-dapr-grpc-port", "50003"
     ]
    depends_on:
      - simpleapi
    network_mode: "service:simpleapi"

  placement:
    image: "daprio/dapr"
    container_name: placement
    command: ["./placement", "-port", "50006"]
    ports:
      - "50006:50006"
    networks:
      - platform

  dashboard:
    image: "daprio/dashboard"
    container_name: dashboard
    ports:
      - "8080:8080"
    networks:
      - platform

networks:
  platform:

来自客户端 API 的测试控制器。

[Route("api/[controller]")]
[ApiController]
public class TestController : ControllerBase
{
    [HttpGet]
    public async Task<ActionResult> Get()
    {
        var httpClient = DaprClient.CreateInvokeHttpClient();
        var response = await httpClient.GetAsync("https://simpleapi/weatherforecast");
        return Ok();
    }
}

这对我的公司来说是一个重大的新项目,如果我们不能尽快完成这项工作,我们将不得不放弃 Dapr 并自己实施一切。

我希望这里有一些明显的问题。

4

1 回答 1

0

实际上结果很简单。

我需要告诉 dapr 使用 ssl。clients-dapr 需要 -app-ssl 参数,因此 clients-dapr 应该如下(simpleapi-dapr 也需要添加相同的参数)

clients-dapr:
    image: "daprio/daprd:edge"
    container_name: clients-dapr
    command: [
      "./daprd",
     "-app-id", "clients",
     "-app-port", "443",
     "-app-ssl",
     "-placement-host-address", "placement:50006",
     "-dapr-grpc-port", "50002"
     ]
    depends_on:
      - clients
    network_mode: "service:clients"
于 2021-05-28T15:44:25.843 回答