简体   繁体   中英

How to continue stream if client is restart in GRPC Server Side Streaming?

    @Override
    public void response(RequestApp request, Grpc.Stub asyncStub) {

        StreamObserver<Dto> streamObserver = new StreamObserver<Dto>() {
            @Override
            public void onNext(Response response) {
                LOGGER.info("Response is received.");
            }

            @Override
            public void onError(Throwable thrwbl) {
                LOGGER.error("Get error.");
            }

            @Override
            public void onCompleted() {
                LOGGER.info("Stream is completed.");
            }
        };

        asyncStub.method(request, streamObserver);
}

The Grpc Client code is like that above. There is server side streaming in here. If the client is restart, after server side stream is started, how to continue this stream ?

You cannot resume a stream in progress if the connection is lost for any reason. If you want the server to start sending data from a previous point in the data stream, you can have the client include a token in the request that the server can use as an indication of where to begin.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM