【发布时间】:2021-01-05 13:18:38
【问题描述】:
gRPC java 实现中 ListenableFuture 风格的存根和异步存根有什么区别?
哪一个用于异步通信?
public static MyServiceStub newStub(io.grpc.Channel channel) {
io.grpc.stub.AbstractStub.StubFactory<MyServiceStub> factory =
new io.grpc.stub.AbstractStub.StubFactory<MyServiceStub>() {
@java.lang.Override
public MyServiceStub newStub(io.grpc.Channel channel, io.grpc.CallOptions callOptions) {
return new MyServiceStub(channel, callOptions);
}
};
return MyServiceStub.newStub(factory, channel);
}
public static MyServiceBlockingStub newBlockingStub(
io.grpc.Channel channel) {
io.grpc.stub.AbstractStub.StubFactory<MyServiceBlockingStub> factory =
new io.grpc.stub.AbstractStub.StubFactory<MyServiceBlockingStub>() {
@java.lang.Override
public MyServiceBlockingStub newStub(io.grpc.Channel channel, io.grpc.CallOptions callOptions) {
return new MyServiceBlockingStub(channel, callOptions);
}
};
return MyServiceBlockingStub.newStub(factory, channel);
}
public static MyServiceFutureStub newFutureStub(
io.grpc.Channel channel) {
io.grpc.stub.AbstractStub.StubFactory<MyServiceFutureStub> factory =
new io.grpc.stub.AbstractStub.StubFactory<MyServiceFutureStub>() {
@java.lang.Override
public MyServiceFutureStub newStub(io.grpc.Channel channel, io.grpc.CallOptions callOptions) {
return new MyServiceFutureStub(channel, callOptions);
}
};
return MyServiceFutureStub.newStub(factory, channel);
}
【问题讨论】: