[英]gRPC protobuffers Java cannot set CallOptions for BlockingStub
I have a simple proto file, to create my java classes 我有一个简单的原始文件,用于创建我的java类
syntax = "proto3";
option java_package = "some.project.grpc";
option java_multiple_files = true;
message PingRequest { }
message PingResponse { }
service MyServer {
rpc Ping(PingRequest) returns (PingResponse);
}
With gradle and the google protobuf plugin ( https://github.com/google/protobuf-gradle-plugin ) I create my classes with 使用gradle和google protobuf插件( https://github.com/google/protobuf-gradle-plugin ),我使用
gradle generateProto
The generated MyServerGrpc
has an internal class MyServerBlockingStub
that has two constructors: 生成的
MyServerGrpc
具有内部类MyServerBlockingStub
,该类具有两个构造函数:
private MyServerBlockingStub(io.grpc.Channel channel) { ... }
private MyServerBlockingStub(io.grpc.Channel channel, io.grpc.CallOptions callOptions) { ... }
The MyServerGrpc
class does expose the first one as newBlockingStub(io.grpc.Channel channel)
but not the second - which I would need. MyServerGrpc
类的确将第一个暴露为newBlockingStub(io.grpc.Channel channel)
但不暴露为第二个-我需要。
Like this, I cannot set any call options, such as timeout. 这样,我无法设置任何呼叫选项,例如超时。 I could easily manipulate the generated file to allow me access to the constructor I need, but those changes would be lost on the next generation - so it's not really an option.
我可以轻松地操纵生成的文件,以允许我访问所需的构造函数,但是这些更改将在下一代中丢失-因此,这实际上不是一个选择。
Since it seems such an easy fix I was thinking: 由于似乎很容易解决,所以我在想:
CallOptions
object somewhere else that I have not found yet? CallOptions
对象设置在我尚未找到的其他地方? MyServerGrpc
extends AbstractStub
. MyServerGrpc
扩展了AbstractStub
。 AbstractStub
has with*
methods mirroring those on CallOptions
. AbstractStub
具有with*
方法,这些方法与CallOptions
上的方法CallOptions
。
So you want to do something like: 因此,您想要执行以下操作:
newBlockingStub(yourChannel).withDeadlineAfter(1, TimeUnit.MINUTES)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.