I am trying to create gRPC client in Quarkus. Did everything according to the documentation.
我正在尝试在Quarkus中创建GRPC客户端。一切都是按照文件做的。
Placed proto files in src/main/proto:
here is the content of the service file
将proto文件放置在src/main/proto中:以下是服务文件的内容
syntax = "proto3";
package userinfo.grpc;
import "UserInfoRequest.proto";
import "UserInfoResponse.proto";
service UserInfoService {
rpc GetUserInfo (UserInfoRequest) returns (UserInfoResponse);
}
added to gradle following dependency:
添加到Gradle的依赖项如下:
implementation 'io.quarkus:quarkus-grpc'
When I built the project I saw my gRPC classes generated in
当我构建项目时,我看到我的GRPC类在
<projectFolder>\build\classes\java\quarkus-generated-sources\grpc\userinfo
My service that is using the gRPC client:
我使用GRPC客户端的服务:
@AllArgsConstructor
@LookupIfProperty(name = "auth.identity-service-enabled", stringValue = "true")
@ApplicationScoped
public class IdentityUserInfoProviderGrpc implements UserInfoProvider {
@GrpcClient("userInfoService")
UserInfoService userInfoService;
//business logic
The problem is that when I run the application I get:
问题是,当我运行应用程序时,我得到:
Blockquote
[error]: Build step io.quarkus.arc.deployment.ArcProcessor#validate threw an exception: jakarta.enterprise.inject.spi.DeploymentException: jakarta.enterprise.inject.UnsatisfiedResolutionException: Unsatisfied dependency for type userinfo.grpc.UserInfoService and qualifiers [@Default]
- java member: <my_package>.userinfo.grpc.IdentityUserInfoProviderGrpc():userInfoService
- declared on CLASS bean [types=[<my_package>.userinfo.UserInfoProvider, java.lang.Object, <my_package>.userinfo.grpc.IdentityUserInfoProviderGrpc], qualifiers=[@Default, @Any], target=<my_package>.userinfo.grpc.IdentityUserInfoProviderGrpc]
The following beans match by type, but none have matching qualifiers:
- Bean [class=userinfo.grpc.UserInfoService, qualifiers=[@Any, @io.quarkus.grpc.GrpcClient("userInfoService")]]
Was trying to add an empty META-INF/beans.xml file in the additional module src/main/resources as well as was trying to add Gradle Jandex plugin, as advised How to create a Jandex index in Quarkus for classes in a external module but did not help.
我试图在附加模块src/main/Resources中添加一个空的META-INF/beans.xml文件,并试图添加Gradle Jandex插件,如建议如何在Quarkus中为外部模块中的类创建Jandex索引,但没有帮助。
I have read few times all the documents Quarkus provided but have not found an explanation for this as I am doing everything as described.
Please help resolve this.
我已经读了几遍Quarkus提供的所有文件,但没有找到对此的解释,因为我正在做所描述的一切。请帮助解决此问题。
Much appreciated.
非常感谢。
更多回答
优秀答案推荐
This looks strange -- as we have plenty of test cases that check / test this.
e.g.
这看起来很奇怪--因为我们有很多测试用例来检查/测试这一点。例如:
Open up a GitHub issue on Quarkus GitHub with a reproducer, and I'll have a look ...
用复制者在Quarkus GitHub上打开GitHub问题,我会看看...
Ah, Clement found it -- you have a trailing space in your client name.
克莱门特找到了--你的客户名字后面有个空格。
@GrpcClient("userInfoService ") // <--- see space at the end
@GrpcClient(“userInfoService”)//<-见末尾空格
vs
VS
The following beans match by type, but none have matching qualifiers: - Bean [class=userinfo.grpc.UserInfoService, qualifiers=[@Any, @io.quarkus.grpc.GrpcClient("userInfoService")]]
以下Bean按类型匹配,但没有一个Bean具有匹配的限定符:-Bean[CLASS=Userinfo.grpc.UserInfoService,QUALIFIERS=[@ANY,@io.quarkus.grpc.GrpcClient(“userInfoService”)]]
Nice catch Clement!
接得好,克莱门特!
更多回答
Created reproducer for you:
为您创建了复制器:
This looks like a Gradle issue on our side ... if I add this pom.xml: gist.github.com/alesj/08c78366c471eb799e9f3c16082cd74b ... and run it with Maven ... it works
这看起来像是我们这边的格雷德问题。如果我添加这个pom.xml:gist.github.com/alesj/08c78366c471eb799e9f3c16082cd74b...和Maven一起运行..。它起作用了
Hi Alesj, i am afraid it was just a typo when putting down the text here in stackoverflow. So it's not related to issue as it is. I was trying both @GrpcClient("userInfoService") UserInfoService userInfoService; and @GrpcClient UserInfoService userInfoService;
你好,Alesj,恐怕只是在Stackoverflow中写下文本时打错了字。因此,这与问题本身并不相关。我同时尝试了@GrpcClient(“userInfoService”)UserInfoService userInfoService和@GrpcClient UserInfoService userInfoService;
我是一名优秀的程序员,十分优秀!