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

Grpc protobuff json support #1029

Open
wants to merge 27 commits into
base: 4.9.x
Choose a base branch
from

Conversation

krickert
Copy link

@krickert krickert commented Mar 2, 2025

gRPC JSON protocol buffer support

#1025 had a quick discussion on this, I found myself converting from JSON to Proto and back often - just so I can read the data a little easier. Since other debugging tools have built in serialization reading, and since a lot of data scientists I work with prefer JSON calls over gRPC.

Per discussion, this feature does the following:

For any grpc project in micronaut, if you annotate a service with @io.micronaut.grpc.annotation.GrpcRestJsonExposed then it will create endpoints based on the service definition and allow for a REST JSON endpoint to proxy grpc requests between JSON and gRPC.

This can be useful in testing situations or for exposing grpc services to front ends using basic HTTP1.1 communication.

This can also be used to quickly serialize between REST services or protocol buffer endpoints.

Finally, if you have this running, it's can be easier to test this via cURL.

This uses the google json parser and printer for the serialization.

Although the concept was simple, it required a lot of testing use cases, but let me know if I missed some use cases and I'll add more tests.

Additions

  • protobuff-json-support - implementation of this feature
  • test-suite-protobuff-json-java - sample end-to-end simple app that demos this feature. I'm doing a quick write up on how to use this. I felt this was needed because it's a better integration test as it's used how people would use it.

will add tests shortly.

got rid of javadoc nagging
… mapper could be a better implementation, but this one we replaced it with is the standard one that comes with google, so that's one less dependency leaving this implmentation to be pure micronaut and google.
creating a grpc service in groovy and cleaned up some check errors
…o get the controller to register when the system is starting. If we force the annotation scan this works, but we need to figure out how to automate that
…o get the controller to register when the system is starting. If we force the annotation scan this works, but we need to figure out how to automate that
krickert added 7 commits March 1, 2025 23:32
Now if you annotate the grpc client you can get a client rest stub, too
…was the same logic to find these methods and invoke them, may as well do it for blocking services and async clients, too. Passes all the same tests successfully
…was the same logic to find these methods and invoke them, may as well do it for blocking services and async clients, too. Passes all the same tests successfully
@krickert
Copy link
Author

krickert commented Mar 3, 2025

I updated this to also support bean registration for grpc clients. Now if someone hands me a grpc service, the act of annotating that bean with @GrpcRestJsonExposed will allow the controller to register that bean for GRPC JSON serialization. Also added support for both async and blocking calls.

I'm going to write a tutorial for these use cases.. but I think we're in pretty good shape as far as the use cases we test for this.

I fell like it's fully featured now - I'll stop adding stuff to it now and see if you can review it.

@krickert
Copy link
Author

krickert commented Mar 4, 2025

@graemerocher how's this look?

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

Successfully merging this pull request may close these issues.

1 participant