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-protoc] Add an option to generate default service methods #3110

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

mgodave
Copy link
Contributor

@mgodave mgodave commented Nov 15, 2024

Motivation

When evolving a service definition that has multiple implementations it is ideal not to break these implementations. Therefore it would be nice if the protoc generator was able to generate default implementations on the service interface to ensure implementations always conform.

Changes

Add an option, defaultServiceMethods to the grpc-protoc stub compiler to generate these default implementation. The result is that service interfaces will provide a default, throwing, implementation of all service RPC interfaces that they implement.

test_service.proto: https://gist.github.com/mgodave/d9064c67da9f365de70ef7526c9eea72


package grpc.netty;

service Tester {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reminder to remove this file before merging PR

printJavaDocs, (__, c) -> {
c.addModifiers(DEFAULT)
.addParameter(GrpcServiceContext, ctx)
.addStatement("throw new UnsupportedOperationException(\"Method " + methodName +
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. gRPC services should use GrpcStatusException with UNIMPLEMENTED status, similar to official grpc-java to be compatible. Consider adding a test in ProtocolCompatibilityTest to make sure our default behavior is the same as grpc-java default behavior. In grpc-netty tests we can always use this new option, no need to create a new test module.
  2. Async RPC that return Single or Publisher can not throw, they should return a failed async source, like Single.failed(...) or Publisher.failed(...).
  3. grpc-java uses fullMethodName() from method descriptor for exception message.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good. I hammered this together to gather feedback on the option. I'll clean things up.

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.

2 participants