Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can you show how to invoke gRPC service with http invoke? #695

Closed
hspaay opened this issue Jun 22, 2022 · 10 comments
Closed

Can you show how to invoke gRPC service with http invoke? #695

hspaay opened this issue Jun 22, 2022 · 10 comments
Assignees

Comments

@hspaay
Copy link

hspaay commented Jun 22, 2022

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: dapr/dapr#2342

Although what is not clear if this requires the gRPC service to implement an onInvoke method as per (dapr/java-sdk#535)

@hspaay hspaay changed the title Can you show hiw to invoke gRPC service with http invoke? Can you show how to invoke gRPC service with http invoke? Jun 22, 2022
@safari137
Copy link

I'm currently stuck on this as well.

@hspaay
Copy link
Author

hspaay commented Jun 23, 2022

@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:

  1. 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.

  2. 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.

  3. 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.

@safari137
Copy link

@hspaay thanks for the explanation! This is very helpful.

@hspaay
Copy link
Author

hspaay commented Jun 24, 2022

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

@paulyuk
Copy link
Contributor

paulyuk commented Jul 23, 2022

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

@msfussell
Copy link
Member

@paulyuk - how would you like to resolve this issue?

@paulyuk
Copy link
Contributor

paulyuk commented Jun 2, 2023

@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.

@yaron2
Copy link
Member

yaron2 commented Jun 2, 2023

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.

@paulyuk paulyuk added wontfix This will not be worked on unsupported labels Jun 2, 2023
@paulyuk
Copy link
Contributor

paulyuk commented Jun 2, 2023

Ok thank you for clarifying. We will not doc or have samples for things we do not support. Thank you both.

@morya
Copy link

morya commented Aug 28, 2024

Using service invocation you can call from HTTP to HTTP, HTTP to gRPC, gRPC to HTTP, and gRPC to gRPC. 
Dapr does not use HTTP for the communication between sidecars, always using gRPC, 
while carrying over the semantics of the protocol used when called from the app. 
Service invocation is the underlying mechanism of communicating with Dapr Actors.

these docs are still in latest version from docs.

as of docs v1.14

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants