I have a simple proto file, to create my java classes
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 generateProto
The generated MyServerGrpc has an internal class MyServerBlockingStub that has two constructors:
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.
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?MyServerGrpc extends AbstractStub. AbstractStub has with* methods mirroring those on CallOptions.
So you want to do something like:
newBlockingStub(yourChannel).withDeadlineAfter(1, TimeUnit.MINUTES)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With