首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >grpc java中ListenableFuture样式存根与异步存根的区别

grpc java中ListenableFuture样式存根与异步存根的区别
EN

Stack Overflow用户
提问于 2021-01-05 13:18:38
回答 1查看 446关注 0票数 0

在gRPC java实现中ListenableFuture样式存根和异步存根有什么不同?

异步通信使用哪一个?

代码语言:javascript
复制
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);
  }
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-01-05 18:37:06

同步与异步存根对通信没有影响。grpc中的存根是通道API之上的一个小空间,存根的不同在于它们是不同的API。只需选择与您希望如何接收响应最接近的存根类型。如果您喜欢异步API,请使用异步API;如果您喜欢未来API,请使用未来API;如果您喜欢同步,则使用同步。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65579699

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档