Closed taojoe closed 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!
@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 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 :)
@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.
@niloc132 Can you give more information about grpc-web servlet filter? Did it deployed?
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:
io.grpc.servlet.jakarta.web.GrpcWebFilter
(from io.deephaven:deephaven-grpc-servlet-jakarta
) serves as an in-process proxy for supporting binary (text is not supported) grpc-web payloads. This can be installed in any servlet container already running the jakarta GrpcServlet, available either from the same artifact or from grpc-java itself. There's nothing to customize, it just works (and will support http/1.1 if your use case does). Note that we don't support javax.servlet, but there's no reason that this couldnt be added. io.grpc.servlet.web.websocket.WebSocketServerStream
(from io.deephaven:deephaven-grpc-servlet-websocket-jakarta
) is a jakarta.websocket.Endpoint
implementation, offering a compatible implementation of the websocket mentioned above - but in-process rather than requiring a proxy. It isn't terribly easy to use - it isn't a "proxy" like the filter above, but instead serves as a replacement for the ServletAdapter from the original PR. Within our own project, we've modified the ServletAdapter
type to let us instantiate this type (and the one in the next point), sharing the transport listener, attributes, etc.io.grpc.servlet.web.websocket.MultiplexedWebSocketServerStream
uses the other subprotocol above, allowing a single websocket to roughly function like a single tcp socket for a set of h2 streams - the first connection requested in this way will be the URL that the client connects to - all future calls/streams will use the same websocket (i.e. the same URL), so each call will send its actual URL as part of the initial request. Both of these implementations can be enabled at the same time, a client will negotiate with whatever it can talk to.@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
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.
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.
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.
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?