0

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)
akortex
  • 5,067
  • 2
  • 25
  • 57
Ragnar
  • 1
  • 1
  • You have redacted the error message, so I can't refer to the class name, but can you show the relevant part of the first `...GrpcService` source code? – Ladicek Oct 04 '21 at 14:55
  • Actually I was able to build the application . Please see the comment regarding the cause of the issue in the code below. But I do not have still fully functional bean , please see also comments in the code and help me figure out was is wrong. – Ragnar Oct 05 '21 at 12:08
  • 1
    Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Oct 09 '21 at 18:01

1 Answers1

-1

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().

Tomerikoo
  • 18,379
  • 16
  • 47
  • 61
Ragnar
  • 1
  • 1