简体   繁体   中英

Dapr GRPC connection Refused while getting state using .net DaprClient

I tried a few links (and trying out suggestions posted ( https://github.com/dapr/dotnet-sdk/issues/609 ) before posting this question, so apologies in advance if this has been repeated before. Would appreciate any pointers. Thanks in advance.

  • I have a .net core application and I am able to save, store and retrieve the state in the self hosted dapr dev environment that comes with dapr_Redis, dapr_zipkin and dapr_placement containers. The app however is running locally and everything works great. I am able to retrieve all the keys from dapr_redis and use them in the application. The command I used to test all this is------------------>

    dapr run --app-id DaprMyApp --dapr-http-port 3500 --components-path./components dotnet run .

  • Now, I have them in a docker-compose file and my app is also containerized (ps: without any Dapr the app runs perfectly fine in docker). When this line executes ----->

  • await daprClient.GetStateEntryAsync <IList <ServicePrincipal>>(storeName, "LightApplications");

    The following error is displayed Dapr.DaprException: State operation failed: the Dapr endpoint indicated a failure. See InnerException for details. ---> Grpc.Core.RpcException: Status(StatusCode="Internal", Detail="Error starting gRPC call. HttpRequestException: Connection refused SocketException: Connection refused", DebugException="System.Net.Http.HttpRequestException: Connection refused ---> System.Net.Sockets.SocketException (111): Connection refused

From the daprd container logs time="2022-03-30T22:23:13.1586783Z" level=info msg="all outstanding components processed" app_id=DaprMyApp instance=6e094eaea3b2 scope=dapr.runtime type=log ver=1.6.1

time="2022-03-30T22:23:13.1588662Z" level=info msg="enabled gRPC tracing middleware" app_id=DaprMyApp instance=6e094eaea3b2 scope=dapr.runtime.grpc.api type=log ver=1.6.1

time="2022-03-30T22:23:13.1589773Z" level=info msg="enabled gRPC metrics middleware" app_id=DaprMyApp instance=6e094eaea3b2 scope=dapr.runtime.grpc.api type=log ver=1.6.1

time="2022-03-30T22:23:13.1592719Z" level=info msg="API gRPC server is running on port 50001" app_id=DaprMyApp instance=6e094eaea3b2 scope=dapr.runtime type=log ver=1.6.1

time="2022-03-30T22:23:13.1598482Z" level=info msg="enabled metrics http middleware" app_id=DaprMyApp instance=6e094eaea3b2 scope=dapr.runtime.http type=log ver=1.6.1

time="2022-03-30T22:23:13.1599458Z" level=info msg="enabled tracing http middleware" app_id=DaprMyApp instance=6e094eaea3b2 scope=dapr.runtime.http type=log ver=1.6.1

time="2022-03-30T22:23:13.1601179Z" level=info msg="http server is running on port 3500" app_id=DaprMyApp instance=6e094eaea3b2 scope=dapr.runtime type=log ver=1.6.1

time="2022-03-30T22:23:13.1601313Z" level=info msg="The request body size parameter is: 4" app_id=DaprMyApp instance=6e094eaea3b2 scope=dapr.runtime type=log ver=1.6. ...... time="2022-03-30T22:23:13.1609711Z" level=info msg="dapr initialized. Status: Running. Init Elapsed 175.1433ms" app_id=DaprCirrus instance=6e094eaea3b2 scope=dapr.runtime type=log ver=1.6.1

  • The docker-compose file looks like

    version: "3.8" services: app: image: DaprMyApp:latest deploy: replicas: 1 ports: - "5001:5001" # - "50001:50001" depends_on: - redis volumes: - type: bind source: c:\trust
    target: /root/.dotnet/https environment: - DAPR_HOST=host.docker.internal - DAPR_GRPC_PORT=50001 - ASPNETCORE_URLS=https://+:5001;http://+:5000

     app-dapr: image: "daprio/daprd:latest" #command: [ "./daprd", "-app-id", "DaprMyApp", "-components-path", "/components" ] command: ["./daprd", "-app-id", "app", "-placement-host-address", "placement:50006", "-dapr-http-port", "3500", "-dapr-grpc-port", "50001", "-components-path", "/components"] ports: - "3500:3500" - "50001:50001" volumes: - "./components/:/components" depends_on: - redis network_mode: "service:app" redis: image: "redis:alpine" ports: - "6379:6379"

StateStore Yaml from Components folder WHen tested in use case 1 redis:6379 was replaced by localhost:6379 when the app was running locally.

apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
  name: statestore
spec:
  type: state.redis
  version: v1
  metadata:
  - name: redisHost
    value: redis:6379
  - name: redisPassword
    value: ""
  - name: actorStateStore
    value: "true"

DataPoint2 When all the containers come up as described in the docker compose file. the following command also works fine (test as described in https://github.com/dapr/dapr/issues/2838 ) Invoke-RestMethod -Method Post -ContentType 'application/json' -Body '[{ "key": "name", "value": "Bruce Wayne"}]' -Uri 'http://localhost:3500/v1.0/state/statestore'

DataPoint3 If i start the sidecar separately ->

  • dapr run --app-id DaprMyApp --dapr-http-port 3500 --components-path./components

  • Check the port displayed for GRPC from above logs Checking if Dapr sidecar is listening on GRPC port 54799 Dapr sidecar is up and running. You're up and running. Dapr logs will appear here.

  • Then add this port to the DAPR_GRPC_PORT to the environment variable of the machine

  • Then run the application separately in another window using dotnet run. Works perfectly,

I was hoping to have the app talk to the DAPR sidecar and get the info from the Redis container all in docker. Thanks in advance for any pointers.

I was able to get this working running with docker-compose up and turn off the swarm mode on my local docker. All 3 containers work fine (daprd, app and redis) and was able to save and retrieve the state from the application in redis. I was previously using docker stack deploy to test.

Thanks

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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