asp.net-coredocker-composedapr

Unable to invoke another service with Dapr


I'm having major problems getting Dapr up and running with my microservices. Every time I try to invoke another service, it returns a 500 error with the message

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

The services and dapr sidecars are currently running in docker-compose on our dev machines but will run in Kubernetes when it is deployed properly.

When I look at the logs for the dapr containers in Docker for Windows, I can see the application being discovered on port 443 and a few initialisation messages but nothing else ever gets logged after that, even when I make my invoke request.

I have a container called clients, which I'm calling an API called test in it and this is then trying to call Microsoft's example weather forecast API in another container called simpleapi.

I'm using swaggerUI to call the apis. The test api returns 200 but when I put a breakpoint on the invoke, I can see the response is 500.

If I call the weatherforecast api directly using swaggerui, it returns a 200 with the expected payload.

I have the Dapr dashboard running in a container and it doesn't show any applications.

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:

Test controller from the Clients 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();
    }
}

This is a major new project for my company and it's looking like we're going to have to abandon Dapr and implement everything ourselves if we can't get this working soon.

I'm hoping there's some glaringly obvious problem here.


Solution

  • Actually turned out to be quite simple.

    I needed to tell dapr to use ssl. The clients-dapr needed the -app-ssl parameter so clients-dapr should have been as follows (the simpleapi-dapr needs the same param adding too)

    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"