fix triple reactor call throws "Too many response for unary method" exception (#14261)

Co-authored-by: caoyanan <caoyanan@growingio.com>
This commit is contained in:
caoyanan666 2024-05-31 16:26:59 +08:00 committed by GitHub
parent d35d7eb30c
commit 95f9984571
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 3 additions and 5 deletions

View File

@ -48,13 +48,11 @@ public final class ReactorServerCalls {
public static <T, R> void oneToOne(T request, StreamObserver<R> responseObserver, Function<Mono<T>, Mono<R>> func) {
try {
func.apply(Mono.just(request))
.switchIfEmpty(Mono.error(TriRpcStatus.NOT_FOUND.asException()))
.subscribe(
res -> {
responseObserver.onNext(res);
responseObserver.onCompleted();
},
responseObserver::onNext,
throwable -> doOnResponseHasException(throwable, responseObserver),
() -> doOnResponseHasException(TriRpcStatus.NOT_FOUND.asException(), responseObserver));
responseObserver::onCompleted);
} catch (Throwable throwable) {
doOnResponseHasException(throwable, responseObserver);
}