-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Proposal: work with grpc-java team to provide binding layer and code generator for grpc-java #360
Comments
@hsyed Seem like a great idea. Do you have any prototype to look at? |
@elizarov our mono repo is built using Bazel I will try and share the code if I can. I based the code generator in our example fromhere. I've made quite some changes to the templates and what they generate but the principal hasn't diverged too far from it. What is good about this generator is that the generated stubs are compatible with grpc-java. This code generator uses mustache templates and an additional external dep from salesforce to generate both of these deps aren't strictly needed. There is another code generator here -- this generates various utility code. It uses "kotlin poet" from square and uses the a proto file parser from square/wire to parse proto files -- kotlin poet is very useful but the proto file parser isn't strictly needed. Here is some example code to see how our generators glue with grpc-java. The binding classes our generators use. Note the generator is different to the open source generator I linked above. Server Stub: Server Streaming
There are a few improvements to be made,
Client Stub: ManyToMany
My thoughts for an end-to-end grpc-kotlin integration encompass the following areas.
|
Really looking forward to this officially becoming a part of Kotlinx.coroutines |
Sounds quite promising. If we can fully take advantage of Kotlin coroutines in gRPC-java, that would simplify the code quite a lot. |
It would be great if backpressure is supported in the form of suspending I once created an extra buffer of messages in addition to the unconfigurable 32kB buffer. It is not very fun having to check |
Just stumbled upon this and Im really interested in contributing to the initial prototype for this. I authored one the code generators mentioned by @hsyed (kroto+). Currently the code generator has dropped its dependency on square/wire and has been refactored into a protoc plugin, but I still feel an official solution would be beneficial to the community. Hopefully reducing the fragmented approaches being provided by the community. Is a process for documenting proposals for coroutines, similar to Kotlins KEEP? If not I can continue working on my initial implementation in preparation for feedback from the community. Also due to the nature of this project, Im not entirely sure where the protoc plugin module should live. I think the integrations directory would be an ill fit. Should it exist in a repo of its own? The generated code will depend on an artifact of its own which I could imaging living in integrations. |
@marcoferrer You are right, it should be a separate module in |
I know its been a while but wanted to give a status update. The PR for the initial implementation has been opened under the kroto-plus repo marcoferrer/kroto-plus#16 and contains all of the code generation and updated apis, along with an example project and snapshot for users to try out. The goal is to release under kroto initially and iterate on the feedback from the users of that project. The plan afterwards will be to port the apis and code gen to this repo. Feedback is welcomed and encouraged. Here are some key points taken from the PR
|
Hi Marco, 2 days ago I started with gRPC and wanted to integrate it into Kotlin with some nice coroutines. Luckily I found your awesome work. This really begs to be included into coroutine integrations. All in all, I thought, somebody must have thought about all this already, here we are. The idea of having the code automatically generated is very nice, but in my case, adding an extra step to the the build is more cumbersome. Why not including also this option in the proposal. Client API:
Usage:
|
Same for messages, with no code generation:
Usage:
|
Hi Mr coder82, I'm totally amazed by your approach, it is a splendid example of Kotlin, protobuf, and coroutines. |
Closing this one. See https://github.com/grpc/grpc-kotlin |
Grpc-java is a low-level api that is quite error prone to use without significant investment in code-generation and libraries encoding relevant concepts --e.g., (pagination, batching, etc.
The go use-case for grpc is much easier to get started with for applications largely due to channels and context propagation being part of the stub generation. Kotlin Coroutines can provide an even better experience out of the box, completely eliminating the need for Streaming libraries or a lot of the utilities provided by a library like gax --e.g., Batching and Paging would be much easier to codify on a per application bases.
At the moment we are prototyping with a glue layer that connects grpc-java concepts per request. The bidi stream use case in this context would code generate a method that creates a job that does:
Channel
to the inputStreamObserver
LinkedListChannel
to the outStreamObserver
.Context::fixedContextExecutor
.This is quite heavy handed. Ideally we should have a fully kotlinx.coroutine based layer perhaps directly above Netty that sidesteps the need to use the grpc-java layer and it would be fully coroutine based from the ground up.
The text was updated successfully, but these errors were encountered: