英文:
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("已接收到响应。");
}
@Override
public void onError(Throwable thrwbl) {
LOGGER.error("发生错误。");
}
@Override
public void onCompleted() {
LOGGER.info("流已完成。");
}
};
asyncStub.method(request, streamObserver);
}
Grpc客户端代码如上所示。其中涉及服务器端流式传输。如果客户端重新启动,在服务器端流式传输开始后,如何继续此流式传输?
英文:
@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 ?
答案1
得分: 1
你不能在连接由于任何原因断开时恢复正在进行的流。如果您希望服务器从数据流中的先前某一点开始发送数据,可以要求客户端在请求中包含一个标记,服务器可以使用该标记来指示从何处开始。
英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论