在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);
}发布于 2021-01-05 18:37:06
同步与异步存根对通信没有影响。grpc中的存根是通道API之上的一个小空间,存根的不同在于它们是不同的API。只需选择与您希望如何接收响应最接近的存根类型。如果您喜欢异步API,请使用异步API;如果您喜欢未来API,请使用未来API;如果您喜欢同步,则使用同步。
https://stackoverflow.com/questions/65579699
复制相似问题