dapr / dotnet-sdk

Dapr SDK for .NET

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

failed to proxy request: required metadata dapr-app-id not found

KunalSaini opened this issue · comments

How to run side car in separate process

Hi, I am adding logic in my web app to publish messages using dapr PubSub component.
I want to run dapr side car separately and configure and run my application in visual studio. So as a first step , i am running
dapr run --log-level debug --app-id orderprocessing --app-port 7286 --resources-path ..\components
and based on the console output, i set the DAPR_HTTP_PORT and DAPR_GRPC_PORT environment in visual studio to debug my application.

When i run my app in visual studio i get, following exception

Unhandled exception. Dapr.DaprException: Publish operation failed: the Dapr endpoint indicated a failure. See InnerException for details.
 ---> Grpc.Core.RpcException: Status(StatusCode="Unknown", Detail="failed to proxy request: required metadata dapr-app-id not found")
   at Dapr.Client.DaprClientGrpc.MakePublishRequest(String pubsubName, String topicName, ByteString content, Dictionary`2 metadata, String dataContentType, CancellationToken cancellationToken)
   --- End of inner exception stack trace ---
   at Dapr.Client.DaprClientGrpc.MakePublishRequest(String pubsubName, String topicName, ByteString content, Dictionary`2 metadata, String dataContentType, CancellationToken cancellationToken)

There is no error log entry in dapr side car output.

I tried setting this dapr-app-id metadata, however still getting the same error.

However if I run the application using dapr cli and everything works fine, including my app publishing messages.

dapr run --log-level debug --app-id orderprocessing --app-port 7286 --resources-path ..\components -- dotnet run --urls https://localhost:7286

Following is my C# code

var obj = new { @event = "test", app = "test" };
await daprClient.PublishEventAsync("pubsub", "lifecycle", JsonSerializer.Serialize(obj),
    new Dictionary<string, string> { { "dapr-app-id", "orderprocessing" } }, stoppingToken);

I am registering dapr client like below, and using DI to resolve the daprClient

services.AddDaprClient();

Following is the dapr version

CLI version: 1.13.0-rc.1
Runtime version: 1.12.5

How can i run dapr process separately and then have my app connect to it.

I think I found out the issue,
i was providing incorrect value for DAPR_GRPC_PORT when running my application,
seems like there are two GRPC servers running

...
time="2024-03-08T15:55:29.4254738-06:00" level=info msg="API gRPC server is running on port 50001" app_id=orderprocessing instance=MA-2M1TDK3 scope=dapr.runtime type=log ver=1.12.5
...
time="2024-03-08T15:55:29.4264712-06:00" level=info msg="HTTP server listening on TCP address: :3500" app_id=orderprocessing instance=MA-2M1TDK3 scope=dapr.runtime.http type=log ver=1.12.5
time="2024-03-08T15:55:29.4264712-06:00" level=info msg="HTTP server is running on port 3500" app_id=orderprocessing instance=MA-2M1TDK3 scope=dapr.runtime type=log ver=1.12.5
...
time="2024-03-08T15:55:29.4264712-06:00" level=info msg="gRPC server listening on TCP address: :58081" app_id=orderprocessing instance=MA-2M1TDK3 scope=dapr.runtime.grpc.internal type=log ver=1.12.5
time="2024-03-08T15:55:29.4264712-06:00" level=info msg="Internal gRPC server is running on port 58081" app_id=orderprocessing instance=MA-2M1TDK3 scope=dapr.runtime type=log ver=1.12.5
...
time="2024-03-08T15:55:29.4264712-06:00" level=info msg="application protocol: http. waiting on port 7286.  This will block until the app is listening on that port." app_id=orderprocessing instance=MA-2M1TDK3 scope=dapr.runtime type=log ver=1.12.5
You're up and running! Dapr logs will appear here.