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 server not starting if proto grammar in maven dependency #15057

Closed
jspasquali opened this issue Feb 13, 2021 · 13 comments
Closed

gRPC server not starting if proto grammar in maven dependency #15057

jspasquali opened this issue Feb 13, 2021 · 13 comments
Labels
area/grpc gRPC area/maven kind/bug Something isn't working

Comments

@jspasquali
Copy link

jspasquali commented Feb 13, 2021

In my setup, there are 2 maven modules:

  • a maven module with the grammar of the service inside src/main/proto/service.proto
  • a maven module with the gRPC implementation + dependency on the grammar module (containing generated java code). The gRPC implementation is a simple class like in the grpc quickstart
@Singleton
public class HandlerService extends MutinyServiceGrpc.ServiceImplBase {
...
}

When compiling and running java -jar target/my-app-1.0.0-SNAPSHOT-runner.jar the grpc server does not start, and grpc-server does not appear in the installed features:

2021-02-13 15:03:08,064 INFO  [io.quarkus] (main) Installed features: [cdi, mutiny, smallrye-context-propagation, vertx]

But if I remove the maven dependency on generated grammar and add the service.proto into the project itself, then the grpc server starts as expected:

2021-02-13 15:04:47,141 INFO  [io.qua.grp.run.GrpcServerRecorder] (vert.x-eventloop-thread-1) gRPC Server started on 0.0.0.0:9000 [SSL enabled: false]
2021-02-13 15:04:47,207 INFO  [io.quarkus] (main) Installed features: [cdi, grpc-server, mutiny, smallrye-context-propagation, vertx]

I would have expected the gRPC feature to be enabled as soon as a gRPC service implementation bean is present, but it seems it works differently. Am I missing something? Should I add something to the project to make the gRPC feature enabled by quarkus?

Environment

  • Output of uname -a or ver:
    MINGW64_NT-10.0 NCEL77941 2.11.2(0.329/5/3) 2018-11-10 14:38 x86_64 Msys
  • Output of java -version:
    java version "11.0.6" 2020-01-14 LTS Java(TM) SE Runtime Environment 18.9 (build 11.0.6+8-LTS) Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.6+8-LTS, mixed mode)
  • Quarkus version or git rev: 1.11.2.Final
  • Build tool (ie. output of mvnw --version or gradlew --version):
    Apache Maven 3.6.3
@jspasquali jspasquali added the kind/bug Something isn't working label Feb 13, 2021
@quarkus-bot
Copy link

quarkus-bot bot commented Feb 13, 2021

/cc @cescoffier, @michalszynkiewicz, @quarkusio/devtools

@michalszynkiewicz
Copy link
Member

@jspasquali thanks for your report!
Is the service implementation class in your Quarkus project?

@jspasquali
Copy link
Author

jspasquali commented Feb 15, 2021

@jspasquali thanks for your report!
Is the service implementation class in your Quarkus project?

Not sure if what you refer with service implementation class is the generated grpc services or the singleton implementation extending from it? I'll try to be more specific:

  • In a first Maven "grammar" module : it contains only the .proto definitions; the pom.xml has dependency on quarkus-grpc + the quarkus-maven-plugin with generate-code goal, so the deliverable contains the generated grammar and services. This grpc API is actually more of a SPI, which can be implemented by multiple "servers".
  • In a second Maven "server impl" module : it is a quarkus project with dependency on previous grammar module + dependency on quarkus-grpc. It contains the Singleton service implementation as shown in original post, that extends from the generated MutinyServiceGrpc.ServiceImplBase coming from the dependency.

If my goal is to share the .proto definition, maybe I should change the approach and not deliver the generated grpc services in the "grammar" module but only deliver .proto files; and generate grpc services in each "server impl" module?

@michalszynkiewicz
Copy link
Member

I meant the singleton.

I think what you describe should work fine. Do you happen to have, or can prepare, a minimal reproducer? It would help me a lot in fixing the issue quickly.

@jspasquali
Copy link
Author

Sure, I'll try to put together a minimal reproducer when possible

@michalszynkiewicz
Copy link
Member

Thanks in advance :)

@jspasquali
Copy link
Author

Here is a reproducer repo : https://github.com/jspasquali/quarkus-grpc-dep-issue
Thanks to have a look!

@michalszynkiewicz
Copy link
Member

michalszynkiewicz commented Feb 17, 2021

The details on what happens are that the grpc-grammar module doesn't have a Jandex index and the grpc-service module doesn't know that the implementation class is an implementation of (I think) BindableService, so it's not discovered.

To fix this, you need to have the grpc-grammar indexed. I think in this case the best way to do it is to add jandex-maven-plugin to it.
You can find details on how to do it, and alternative solutions, here: https://stackoverflow.com/questions/55513502/how-to-create-a-jandex-index-in-quarkus-for-classes-in-a-external-module

@jspasquali
Copy link
Author

jspasquali commented Feb 18, 2021

Thanks @michalszynkiewicz, I forgot about this jandex thing... I tried with empty beans.xml and with jandex plugin, both are indeed valid solutions.
It is a bit unfortunate this deeper level of knowledge is needed for simple things, this jandex indexing is not something you typically understand by browsing a few quarkus guides!

@michalszynkiewicz
Copy link
Member

True, it would be good to have this info in the gRPC guide. I added this to my todo list.

@nastra
Copy link
Contributor

nastra commented Aug 16, 2021

+1 on adding this to the gRPC guide. I ran into this problem and found this issue here and it can be fixed by #15057 (comment)

nastra added a commit to nastra/quarkus that referenced this issue Aug 17, 2021
People seem to be running into
quarkusio#15057 (including myself)
because a Jandex Index is missing, thus we should update the gRPC
Getting Started Guide and mention this.
@nastra
Copy link
Contributor

nastra commented Aug 17, 2021

@michalszynkiewicz I opened #19441 that updates the gRPC guide. Do you have some free cycles to review it?

@michalszynkiewicz
Copy link
Member

@nastra thanks a lot :)

nastra added a commit to nastra/quarkus that referenced this issue Aug 17, 2021
People seem to be running into
quarkusio#15057 (including myself)
because a Jandex Index is missing, thus we should update the gRPC
Getting Started Guide and mention this.
nastra added a commit to nastra/quarkus that referenced this issue Aug 17, 2021
People seem to be running into
quarkusio#15057 (including myself)
because a Jandex Index is missing, thus we should update the gRPC
Getting Started Guide and mention this.
nastra added a commit to nastra/quarkus that referenced this issue Aug 17, 2021
People seem to be running into
quarkusio#15057 (including myself)
because a Jandex Index is missing, thus we should update the gRPC
Getting Started Guide and mention this.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/grpc gRPC area/maven kind/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants