dotnet-sdk icon indicating copy to clipboard operation
dotnet-sdk copied to clipboard

Support gRPC stream consuming from DaprClient

Open tomflenner opened this issue 6 months ago • 1 comments

Describe the feature

Currently, the DaprClient in the .NET SDK supports unary calls over gRPC but does not provide a way to consume gRPC server streaming responses (e.g., when a Dapr sidecar or component emits a continuous stream of messages).

We propose extending DaprClient to support consuming gRPC streaming endpoints exposed by Dapr, similar to how InvokeMethodGrpcAsync works for unary calls, but using an IAsyncEnumerable<T> return type or a callback-based approach for stream consumption.

This would enable advanced use cases where clients want to react to streaming gRPC.

Suggestion for API Surface

IAsyncEnumerable<TResponse> InvokeMethodGrpcAsync<TResponse>(
    string appId,
    string methodName,
    CancellationToken cancellationToken = default);

IAsyncEnumerable<TRequest, TResponse> InvokeMethodGrpcAsync<TRequest, TResponse>(
    string appId,
    string methodName,
    CancellationToken cancellationToken = default);

Dapr already support this : https://docs.dapr.io/developing-applications/building-blocks/service-invocation/howto-invoke-services-grpc/#proxying-of-streaming-rpcs (thanks @JoshVanL for pointing this out during our research).

This is require to write a gRPC client without using Dapr .NET SDK.

Release Note

RELEASE NOTE: ADD Support for consuming gRPC server streams via DaprClient in the .NET SDK.

tomflenner avatar Jun 05 '25 15:06 tomflenner

There is a version of consuming gRPC stream in .NET from a Python gRPC server on this branch : https://github.com/tomflenner/dapr-service-to-service-invocation-http-stream-issue/tree/grpc

Currently, the README was not being updated according to the usage of gRPC so the code itself is the documentation and probably need love, it was just a quick POC to illustrate a theory.

tomflenner avatar Jun 05 '25 15:06 tomflenner