Add gRPC-JSON transcoding prototype - #424
Conversation
Generate Spring MVC endpoints from supported google.api.http annotations and route requests through the in-process gRPC server. [resolves spring-projects#339] Signed-off-by: Aleksander Brzozowski <olek.brzozowski@gmail.com>
|
Thanks for doing this. I don't love the code generation approach to be honest. It should be possible to do everything in statically compiled code using functional endpoints. Also not sure I like the in-process channel, but I understand why you did that. The main thing I dislike about that is the need for a I guess supporting only unary rpc methods was just a proof of concept? There's no technical reason why streaming methods wouldn't work? |
How do you see this? I thought that codegen allows us to fail compilation whenever some feature that is not supported is being used, or some other error happens that we can detect early (when compared to failing in runtime).
Yep, probably something that can be controlled. If we don't want to use the in-process channel, then what? Find the bean that implements the server and call the method directly?
Yep, exactly, I haven't even investigated how to support them. |
Summary
Add an experimental
spring-grpc-transcodingmodule that generates Spring MVCcontrollers from supported
google.api.httpannotations and forwards HTTP/JSONrequests through the application's in-process gRPC server.
Resolves #339.
Motivation
Spring gRPC applications currently need to maintain a separate HTTP adapter when a
service must also be available to JSON clients. This prototype demonstrates a small,
strictly validated transcoding path that derives the adapter from the protobuf
contract while preserving the existing gRPC service implementation and server
interceptor chain.
Architecture
CodeGeneratorRequestdescriptors,resolves annotated unary methods, validates the supported
HttpRulesubset andemits one package-private Spring MVC controller per annotated service.
blocking stub and call it over a named in-process channel.
GrpcTranscodingConfigurationis an explicit opt-in configuration that providesthe channel and
ProtobufJsonFormatHttpMessageConverter. The channel is createdthrough
GrpcChannelFactory, includes global client interceptors, uses the directexecutor and remains lifecycle-owned by the factory.
method context; they are not silently skipped or reinterpreted.
Supported subset
java_multiple_files = true.stringpath variables.stringquery fields when there is no request body.body: "*"decoded as the concrete protobuf request.Deliberate deferrals
PATCH and custom verbs, named bodies, nested or constrained path templates,
additional_bindings,response_body, streaming RPCs, non-string or repeatedpath/query fields,
HttpBody, HTTP/gRPC metadata propagation and a library-definedHTTP error response contract are outside this initial prototype.
Setup
Add
spring-grpc-transcodingto the application and protoc plugin classpaths,register its JAR as a
jvm-mavenprotobuf plugin, importGrpcTranscodingConfiguration, and configure the same in-process server name onboth sides (default:
grpc-transcoding). The reference documentation and samplecontain complete Maven and protobuf examples.
Verification
javaccompilation of generated controllers.body: "*", path precedence,duplicate queries and interceptor execution.