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 MP Implementation #8878

Merged
merged 30 commits into from
Jul 23, 2024
Merged

gRPC MP Implementation #8878

merged 30 commits into from
Jul 23, 2024

Conversation

spericas
Copy link
Member

@spericas spericas commented Jun 12, 2024

Description

Integration of H3 gRPC MP Implementation into H4. gRPC in H3 MP started its own Netty-based server on a new port, the new implementation in H4 is fully intergrated with the web server, which is now capable of detecting the type of a connection and route its data to the correct handler. As a result of this new integration, there is new gRPC server configuration (there is no gRPC server anymore) and a few other integration points have changed.

Module Changes

  • New helidon-microprofile-grpc-core module
  • New helidon-microprofile-grpc-server module
  • Additions and updates to helidon-grpc-core and helidon-webserver-grpc modules

gRPC MP Support

Just like in H3, there is now support for gRPC annotated endpoints:

    @Grpc.GrpcService
    @ApplicationScoped
    public static class EchoService {

        @Grpc.Unary("Echo")
        public void echo(Echo.EchoRequest request, StreamObserver<Echo.EchoResponse> observer) {
            try {
                String message = request.getMessage();
                Echo.EchoResponse response = Echo.EchoResponse.newBuilder().setMessage(message).build();
                complete(observer, response);
            } catch (IllegalStateException e) {
                observer.onError(e);
            }
        }
    }

In addition to annotated endpoints, the gRPC CDI extension will scan and automatically register any beans that implement GrpcService (from SE) and BindableService (io.grpc), just like it did in H3.

Server interceptors from the io.grpc API are support only on annotated types either by direct reference using the @GrpcInterceptors or via CDI name binding.

    @Grpc.GrpcService
    @ApplicationScoped
    @EchoInterceptorBinding       // name binding
    @Grpc.GrpcInterceptors(EchoInterceptor1.class)   // direct reference
    public static class EchoService { ... }

    @Grpc.GrpcInterceptor
    @ApplicationScoped
    public static class EchoInterceptor1 implements ServerInterceptor {

        @Override
        public <ReqT, RespT> ServerCall.Listener<ReqT> interceptCall(ServerCall<ReqT, RespT> call,
                                                                     Metadata headers,
                                                                     ServerCallHandler<ReqT, RespT> next) {
            ...
        }
    }

    @Grpc.GrpcInterceptor
    @EchoInterceptorBinding
    @ApplicationScoped
    public static class EchoInterceptor2 implements ServerInterceptor {

        @Override
        public <ReqT, RespT> ServerCall.Listener<ReqT> interceptCall(ServerCall<ReqT, RespT> call,
                                                                     Metadata headers,
                                                                     ServerCallHandler<ReqT, RespT> next) {
            ...
        }
    }

Additional Features in PR

  • The GrpcMpContext SPI has also been ported to H4. It enables users to write CDI extensions that are given access to the CDI BeanManager and the server's GrpcRouting builder.
  • A Context interceptor is automatically registered for all annotated endpoints
  • A Tracing interceptor is registered for all annotated endpoints if grpc.tracing.enabled is set to true (defaults tofalse)

spericas added 7 commits June 4, 2024 09:29
…classes to helidon-grpc module.

Signed-off-by: Santiago Pericas-Geertsen <santiago.pericasgeertsen@oracle.com>
…still incomplete, but module now compiles.

Signed-off-by: Santiago Pericas-Geertsen <santiago.pericasgeertsen@oracle.com>
Signed-off-by: Santiago Pericas-Geertsen <santiago.pericasgeertsen@oracle.com>
Signed-off-by: Santiago Pericas-Geertsen <santiago.pericasgeertsen@oracle.com>
Signed-off-by: Santiago Pericas-Geertsen <santiago.pericasgeertsen@oracle.com>
Signed-off-by: Santiago Pericas-Geertsen <santiago.pericasgeertsen@oracle.com>
@spericas spericas marked this pull request as draft June 12, 2024 14:02
@oracle-contributor-agreement oracle-contributor-agreement bot added the OCA Verified All contributors have signed the Oracle Contributor Agreement. label Jun 12, 2024
Signed-off-by: Santiago Pericas-Geertsen <santiago.pericasgeertsen@oracle.com>
spericas added 2 commits June 18, 2024 10:03
Signed-off-by: Santiago Pericas-Geertsen <santiago.pericasgeertsen@oracle.com>
Signed-off-by: Santiago Pericas-Geertsen <santiago.pericasgeertsen@oracle.com>
spericas added 2 commits June 18, 2024 12:42
Signed-off-by: Santiago Pericas-Geertsen <santiago.pericasgeertsen@oracle.com>
Signed-off-by: Santiago Pericas-Geertsen <santiago.pericasgeertsen@oracle.com>
@spericas spericas force-pushed the issue-8794 branch 2 times, most recently from efbc4c9 to 20cbf3b Compare June 18, 2024 19:54
Signed-off-by: Santiago Pericas-Geertsen <santiago.pericasgeertsen@oracle.com>
@spericas spericas changed the title [draft] gRPC MP Implementation gRPC MP Implementation Jun 20, 2024
@spericas spericas marked this pull request as ready for review June 20, 2024 13:11
@spericas spericas force-pushed the issue-8794 branch 2 times, most recently from 00e2c50 to 6e6e1f0 Compare June 21, 2024 18:03
Signed-off-by: Santiago Pericas-Geertsen <santiago.pericasgeertsen@oracle.com>
Copy link
Member

@tomas-langer tomas-langer left a comment

Choose a reason for hiding this comment

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

  • I think the annotations should be in helidon-microprofile-grpc-api module
  • please make sure all public constructors are replaced with factory methods (unless they are allowed by our guidelines)
  • please make sure we never accept null as a parameter value

There is a lot of reflection used here. It may be better to use annotation processing to generate all the needed stuff to be reflection free (maybe even use ServiceRegistry for this?).

bom/pom.xml Show resolved Hide resolved
grpc/core/pom.xml Outdated Show resolved Hide resolved
grpc/core/pom.xml Outdated Show resolved Hide resolved
microprofile/grpc/server/src/main/java/module-info.java Outdated Show resolved Hide resolved
microprofile/grpc/server/src/main/java/module-info.java Outdated Show resolved Hide resolved
microprofile/grpc/server/src/main/java/module-info.java Outdated Show resolved Hide resolved
webserver/grpc/pom.xml Show resolved Hide resolved
spericas added 4 commits July 2, 2024 15:50
…backward compatibility.

Signed-off-by: Santiago Pericas-Geertsen <santiago.pericasgeertsen@oracle.com>
Signed-off-by: Santiago Pericas-Geertsen <santiago.pericasgeertsen@oracle.com>
Signed-off-by: Santiago Pericas-Geertsen <santiago.pericasgeertsen@oracle.com>
Signed-off-by: Santiago Pericas-Geertsen <santiago.pericasgeertsen@oracle.com>
Signed-off-by: Santiago Pericas-Geertsen <santiago.pericasgeertsen@oracle.com>
Signed-off-by: Santiago Pericas-Geertsen <santiago.pericasgeertsen@oracle.com>
@spericas spericas force-pushed the issue-8794 branch 3 times, most recently from 52564dd to efb4400 Compare July 5, 2024 19:25
…r testing gRPC.

Signed-off-by: Santiago Pericas-Geertsen <santiago.pericasgeertsen@oracle.com>
…enever possible. A few other minor changes to follow our coding rules.
…hare annoations and types with future declarative SE API.

Signed-off-by: Santiago Pericas-Geertsen <santiago.pericasgeertsen@oracle.com>
…Service.

Signed-off-by: Santiago Pericas-Geertsen <santiago.pericasgeertsen@oracle.com>
@spericas spericas merged commit 7c40eb8 into helidon-io:main Jul 23, 2024
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
OCA Verified All contributors have signed the Oracle Contributor Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants