Java中GRPC的NewBlockingStub中的异常线程
我是GRPC的新手。使用原始文件创建Java存根后,我在发送new Blocking
生成的Java存根文件的loginapi
从客户端发送存根。服务器正在启动,但客户端获得了例外。
客户端代码:
userBlockingStub userStub = userGrpc.newBlockingStub(channel);
生成的Java存根文件:
public static userBlockingStub newBlockingStub(io.grpc.Channel channel) {
return new userBlockingStub(channel);
}
获取此例外:
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
at com.grpc.userGrpc.newBlockingStub(userGrpc.java:106)
at grpcClient.grpcClient.main(grpcClient.java:19)
有任何解决方案吗?
I am new to gRPC. After creating java stubs using a proto file, I am getting an exception in the newBlocking
stub of the generated java stub file when sending a loginAPI
request from client. The server is starting, but the client getting an exception.
Client code:
userBlockingStub userStub = userGrpc.newBlockingStub(channel);
generated Java stub file:
public static userBlockingStub newBlockingStub(io.grpc.Channel channel) {
return new userBlockingStub(channel);
}
Getting this exception:
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
at com.grpc.userGrpc.newBlockingStub(userGrpc.java:106)
at grpcClient.grpcClient.main(grpcClient.java:19)
Is there any solution?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,当您尝试实现
grpc
通信时,因此您可能拥有多个服务(项目),您希望将它们传达给它们。我本人实现了一个单独的项目
grpc-interface
并将其添加到git存储库中,然后我可以使用git-submodule subpodule
代码>我需要传达的服务(项目)的功能。我实现了我的
grpc-interface
如下:这是我的
build.gradle
文件,您可以找到带有小R& d的maven
版本也很容易:然后我创建了一个
.proto
文件来介绍我的服务及其请求和响应模型:在此步骤之后,您需要编译该项目,并且将导致使用
生成的在您的
main
软件包旁边的名称。然后,正如我说的那样,如果您将该项目放入诸如git之类的存储库中,则需要使用
git-submodule
功能将其添加到您的项目中,当然,还有其他方法可以将其添加到您的项目中项目和git-submodule
不是必须的!只需考虑一下,将此模块添加到项目之后,在运行和编译主项目之前,您需要编译
grpc-interface
,以便您的项目可以使用生成的文件喜欢:现在我有两个服务,名为
withs-manager
和会计>会计
我想传达,正如您在我的.proto
文件中看到的那样,我希望我的财富
服务来请求并从我的Accounting
服务中检查用户余额。在我的
财富
服务中,我在服务层中所做的服务:}
以及在我的
Accounting
服务中,我为grpc
服务创建了类:我本人曾与
grpc
争论很多,直到我可以解决它,希望我的经验也可以帮助您解决自己的能力。First of all, when you are trying to implement a
gRPC
communication, so you have probably more than one service(project) that you want them to be communicated.I myself implemented a separate project
grpc-interface
and added it to the Git repository, then I could add this project as asubmodule
using theGit-submodule
feature to my services(projects) that I needed to be communicated.I implemented my
grpc-interface
as below:here is my
build.gradle
file, you can find theMaven
version with a little R&D easily too:Then I created a
.proto
file to introduce my service and its request and response model:After this step, you need to compile the project and it will result in creating a package with a
generated
name beside yourmain
package.Then, as I said if you put this project in a repository like Git, you need to add it to your projects using the
Git-submodule
feature, of course, there are other ways to add it to your projects andGit-submodule
is not a MUST!just consider that, after adding this module to your projects, before running and compiling the main project you need to compile your
grpc-interface
so that your project can use generated files that is like:Now I have two services, named
wealth-manager
andaccounting
that I want to be communicated, as you saw in my.proto
file, I want mywealth
service to request and check the user balance from myaccounting
service.in my
wealth
service I did as below in my Service layer:}
And in my
accounting
service I have created class forgrpc
services as below:I myself have argued with
gRPC
a lot until I could resolve it, hope my experience with it helps you to resolve yours too.