Quarkus gRPC build issue

783 Views Asked by At

Following this blog related to consuming gRPC services in quarkus https://quarkus.io/guides/grpc-service-consumption

Successfully generated code from proto files provided by api provider by running 'mvn compile'.

But got the error when trying to build the app

“only Mutiny service interfaces, blocking stubs, reactive stubs based on Mutiny and io.grpc.Channel can be injected via @GrpcClient”

./mvnw clean package -Dmaven.test.skip

...
[error]: Build step io.quarkus.grpc.deployment.GrpcClientProcessor#discoverInjectedGrpcServices threw an exception: javax.enterprise.inject.spi.DeploymentException: ...ServiceGrpc cannot be injected into ...ServiceGrpc - only Mutiny service interfaces, blocking stubs, reactive stubs based on Mutiny and io.grpc.Channel can be injected via @GrpcClient

[ERROR]         at io.quarkus.grpc.deployment.GrpcClientProcessor.invalidInjectionPoint(GrpcClientProcessor.java:282)
[ERROR]         at io.quarkus.grpc.deployment.GrpcClientProcessor.discoverInjectedGrpcServices(GrpcClientProcessor.java:170)
[ERROR]         at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[ERROR]         at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
[ERROR]         at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[ERROR]         at java.base/java.lang.reflect.Method.invoke(Method.java:568)
[ERROR]         at io.quarkus.deployment.ExtensionLoader$2.execute(ExtensionLoader.java:820)
[ERROR]         at io.quarkus.builder.BuildContext.run(BuildContext.java:277)
[ERROR]         at org.jboss.threads.ContextHandler$1.runWith(ContextHandler.java:18)
[ERROR]         at org.jboss.threads.EnhancedQueueExecutor$Task.run(EnhancedQueueExecutor.java:2449)
[ERROR]         at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1478)
[ERROR]         at java.base/java.lang.Thread.run(Thread.java:833)
[ERROR]         at org.jboss.threads.JBossThread.run(JBossThread.java:501)
1

There are 1 best solutions below

1
On

Fixed the issue with the build by changing the injection , please see my code below. But still not able to get it working fully , please see details in the comments as well:

public class SendMsgService {
    //THIS INJECTION WAS CAUSING THE  ISSUE WITH THE BUILD
    // @GrpcClient("msg-service")
    // ServiceGrpc.ServiceStub stubInjected;

    @GrpcClient("msg-service")
    MutinyServiceGrpc.MutinyServiceStub stubInjected;

    MutinyServiceGrpc.MutinyServiceStub stubPojo = MutinyServiceGrpc.newMutinyStub(Utils.getChannelUrlStr()); 

    @GET
    @Path("/send-message/{message}")
    public void send(@PathParam("message") String message) {
        var msg = Utils.buildMessage(message);
        BearerToken token = new BearerToken(ApiCredentials.getClientCredentialSource()::accessToken);

        //THIS IS WORKING
        stubPojo.withCallCredentials(token).sendTextToSubscriberAsOperator(msg).subscribe().with(item -> System.out.println(item),failure -> System.out.println("Failed with " + failure));

        //THIS IS NOT WORKING
        //stubInjected.withCallCredentials(token).sendTextToSubscriberAsOperator(msg).subscribe().with(item -> System.out.println(item),failure -> System.out.println("Failed with " + failure));

        System.out.println("Msg has been sent");
    }

application.properties has also the var quarkus.grpc.clients.msg-service.host with the same value as Utils.getChannelUrlStr().