grpc / grpc-web

gRPC for Web Clients
https://grpc.io
Apache License 2.0
8.56k stars 762 forks source link

when will In-process proxies be ready? #1207

Closed taojoe closed 2 years ago

taojoe commented 2 years ago

the java version in-process proxies has some issue, the request will do 3 times to grpc service, while the client does 1 time. and the java version match request to java code, java codes may have prefix packages, it's not transparent, it may need to change some code in the in-process proxies java code.

it there a plan to support in-process proxies offically?

sampajano commented 2 years ago

Thanks for asking!

Sorry unfortunately that the Java in-process proxy project is on hold right now and is not being actively supported at this moment.. (I'll make a documentation update to mention so..)

Apologize for any inconveniences!

pbi-qfs commented 2 years ago

@sampajano May you elaborate a bit on why you put the development of the java proxy on hold? Is it due to manpower or do you have other doubts?

In some scenarios (e.g. running a grpc-based electron app locally with embedded app server), you cannot use envy in a docker container (since obviously you do not want a user to install docker on his desktop pc just to start an otherwise self contained app) and go requires different binaries for different operating systems, so you loose the portability of your app. The Java proxy is your redemption here...

sampajano commented 2 years ago

@sampajano May you elaborate a bit on why you put the development of the java proxy on hold? Is it due to manpower or do you have other doubts?

No particular doubts that i'm aware of.. Mainly just prioritizations.. :)

Sorry for your inconveniences.. we encourage you to look for other ecosystem solutions too :)

niloc132 commented 2 years ago

@pbi-qfs over at https://github.com/grpc/grpc-java/pull/8596 we have a grpc servlet that works with either javax.servlet or jakarta.servlet apis, and provides application/grpc support. I have since developed an application/grpc-web servlet filter that can stand in front of that grpc servlet, and transparently hand off all handling to it. This approach differs from the connector repo, which directly creates the java service by expected name (using reflection, avoiding ServiceDefinitions and interceptors), and as such might be more generally useful.

wirekang commented 1 year ago

@niloc132 Can you give more information about grpc-web servlet filter? Did it deployed?

niloc132 commented 1 year ago

Sorry for the delay @wirekang - I hope the details in this writeup are helpful for you:

Yes, it works great. Unfortunately, the previous issue took a very long time to resolve, and we've basically reached a stable state... and stability is a terrible condition for "let's spend a bunch of time on this!" even to do a writeup.

If you (and this grpc/grpc-java's maintainers) would be amenable, open an issue for this in grpc-java and I'll see about contributing our work? that seems to be a more appropriate place than this repo.

Here's a summary of what we know, condensed to bullet points.

Our conclusions:

jazdw commented 4 months ago

@niloc132 I wish I had seen your comment earlier, I had no idea there was support for gRPC-Web in grpc-java. We modified the old Servlet code from this repo and made it conformant with the Connect conformance tests for gRPC-Web. https://github.com/RadixIoT/grpc-web-java

niloc132 commented 4 months ago

Thanks for the link - going from the README, it appears that your project works a little differently than what I described, as yours functions as a proxy (default implementation is a separate gRPC client... via InProcessChannelBuilder) while the code I shared above is just translation so that the same Java gRPC server can offer both gRPC and gRPC-web without the need of a proxy (which greatly simplifies local development or simple deployments). Yours might give you some flexibility that we weren't concerned with right away, but I suspect will be somewhat heavier overall. I played with adding a proxy implementation, but never got far enough to be worth publishing anything (and it never was necessary for our purposes).

Feel free to contact me via email if you want to discuss further, my email is on my commits.

jazdw commented 4 months ago

Thanks for the link - going from the README, it appears that your project works a little differently than what I described, as yours functions as a proxy (default implementation is a separate gRPC client... via InProcessChannelBuilder)

Yep, indeed it does. It will allow you to configure routing services to different channels, which could be in-process or an external gRPC server via TCP/TLS.

while the code I shared above is just translation so that the same Java gRPC server can offer both gRPC and gRPC-web without the need of a proxy (which greatly simplifies local development or simple deployments).

As I understand it you would have to be running a gRPC server via a servlet instead of via Netty right?

Yours might give you some flexibility that we weren't concerned with right away, but I suspect will be somewhat heavier overall.

Yes most likely.

niloc132 commented 4 months ago

As I understand it you would have to be running a gRPC server via a servlet instead of via Netty right?

Correct - we went down this path because the grpc-netty codebase makes it extremely difficult to add some other in-process grpc-web handler at all. We have found no appreciable difference for our use cases between the netty vs servlet (for which we are using Jetty 11) implementation in terms of gRPC performance, and using a servlet makes it not only possible to add grpc-web to the server, but also offer other static web resources.