quickstarts
quickstarts copied to clipboard
Can you show how to invoke gRPC service with http invoke?
Ask your question here
Following the helpful go quickstart service_invocation works like a charm. When I'm converting it to use gRPC with protobuf that works as well. However, invoking the gRPC using the dapr http API doesn't work and results into 503 Service Unavailable. Would it be possible to include this cross-protocol as an example in the quickstart?
Update: link to issue that suggests this should work: https://github.com/dapr/dapr/issues/2342
Although what is not clear if this requires the gRPC service to implement an onInvoke method as per (https://github.com/dapr/java-sdk/issues/535)
I'm currently stuck on this as well.
@safari137 got it working by implementing the UnimplementedAppCallbackServer which defines an OnInvoke method. This is described in the integrations example here: https://docs.dapr.io/developing-applications/integrations/grpc-integration/. This allows a call into your service via HTTP. The onInvoke method should check the 'in.Method' property and pass the request to your service handler.
My current understanding after this early bit of experimentation with implementing a dapr gRPC service:
-
The gRPC service can be invoked via dapr's gRPC port as shown in the docs (gRPC->gRPC). There is no dependency on dapr to get this to work.
-
To invoke the service via dapr's HTTP API, the service must implement dapr's callback API, check the in.Method property to determine which service method to invoke, map the provided parameters to your service method parameters and do the type checking and validation. Now the service has become dependent on dapr. The service gRPC API is not used. You implement support for cross protocol yourself but at least you get the benefit of using dapr's HTTP middleware chain.
-
When the service wants to use dapr's pub/sub feature it also needs to implement the same callback API, but I haven't tested this yet.
I'm going to work on a more elaborate sample service to test this out including pub/sub and http middleware. It would be nice if the documentation would explain this a bit better or if there is example code that does this. Hope this helps.
@hspaay thanks for the explanation! This is very helpful.
In case anyone else wonders how to do this. This simple echo service demonstrates grpc->grpc and http->grpc invocation. Repo can be found here: https://github.com/wostzone/echo-service
Thank you much for the contribution @hspaay.
The recommendation we have for Invoke is to use gPRC proxy
, which is essentially setting the dapr-app-id
header, and then just making the gRPC call as normal and/or using your proto. We believe this is better than using Dapr SDK's invoke API believe it or not.
I believe you nail this here: https://github.com/wostzone/echo-dapr/blob/main/pkg/plain-grpc/client/main.go#L70 Maybe it's worth just calling this out?
Note we have docs and how-to's for this approach here: https://docs.dapr.io/developing-applications/building-blocks/service-invocation/howto-invoke-services-grpc/#step-2-invoke-the-service
@paulyuk - how would you like to resolve this issue?
@yaron2 what do you recommend here? I feel it's cool there is an integration in the doc above. I wonder how much we feel this should be our guidance? For now I recommend we keep pointing to the doc, and not alter quickstarts.
gRPC proxying is for gRPC to gRPC communication. The detailed reply by @hspaay above covers how you would achieve HTTP to gRPC, however since then we have deprecated the OnInvoke method and HTTP to gRPC isn't a recommended scenario, so shouldn't be in either docs nor quickstarts.
Ok thank you for clarifying. We will not doc or have samples for things we do not support. Thank you both.