grpc未来的存根故障

时间:2018-03-22 07:16:46

标签: java asynchronous grpc

我正在创建一个这样的非阻塞存根:

stub = ServiceGrpc.newFutureStub(channel);

然后,当我拨打电话时,我会使用以下内容:

ListenableFuture<SearchSubscriberResponse> searchSubscriberResponse = stub.withDeadlineAfter(timeout, TimeUnit.MILLISECONDS).searchSubscriber(searchSubscriberRequest);
Futures.addCallback(searchSubscriberResponse, futureCallback);

回调有两个选项,我看到了:

void onSuccess(@Nullable V var1);
void onFailure(Throwable var1);

在我的情况下,DEADLINE_EXCEEDED经常发生,但是onFailure只有一个Throwable参数,那么我怎样才能与产生失败的请求相关联?或者不是吗?

1 个答案:

答案 0 :(得分:2)

You can use a different futureCallback for each request.

ListenableFuture<SearchSubscriberResponse> searchSubscriberResponse = stub
    .withDeadlineAfter(timeout, TimeUnit.MILLISECONDS)
    .searchSubscriber(searchSubscriberRequest);
Futures.addCallback(searchSubscriberResponse,
    new YourFutureCallback(searchSubscriberRequest));