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”</p>

./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)
4

1 回答 1

0

通过更改注入修复了构建问题,请参阅下面的代码。但仍然无法使其完全正常工作,请参阅评论中的详细信息:

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也有与 varquarkus.grpc.clients.msg-service.host具有相同值的 var Utils.getChannelUrlStr()

于 2021-10-05T12:21:36.650 回答