I init my rsocket client with retry as follow:
Mono<RSocketRequester> requesterMono = rsocketRequesterBuilder.setupRoute(SETUP_ROUTE)
.setupData(new ObjectMapper().writeValueAsString(getAuthInfo()))
.dataMimeType(MimeTypeUtils.parseMimeType(WellKnownMimeType.APPLICATION_JSON.getString()))
.rsocketConnector(connector -> connector.acceptor(responder)
.fragment(MTU_BYTE_SIZE)
.keepAlive(Duration.ofSeconds(KEEP_ALIVE_INTERVAL_SEC), Duration.ofSeconds(KEEP_ALIVE_MAX_TIME_SEC))
.reconnect(Retry.fixedDelay(Integer.MAX_VALUE, Duration.ofSeconds(RSOCKET_RETRY_INTERVAL_SECONDS))
.doAfterRetry(retrySignal -> log.warn("RSocket client is reconnecting to get the newest connection...."))))
.connect(TcpClientTransport.create(TcpClient.create()
.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, sidecarConfig.getRConnectTimeOutMs())
.option(ChannelOption.SO_KEEPALIVE, true)
.option(ChannelOption.TCP_NODELAY, true)
.host(consoleDomain)
.port(sidecarConfig.getConsoleRSocketPort())
.secure(ssl -> ssl.sslContext(sslContext))));
requesterMono.block(Duration.ofSeconds(FIRST_WAIT_TIMEOUT_SEC)).rsocket().onClose().doOnError(error -> {
String errMsg = "[RSOCKET] connection close by fatal error, and client will exit.msg: " + ExceptionUtils.getRootCauseMessage(error);
log.error(errMsg, error);
doExit();
}).doFinally(consumer -> log.info("[RSOCKET] sidecar client DISCONNECTED to console")).subscribe();
What I expected: Only fatal error will cause client to exit and when client meet other common exception like connection exception and error, it can retry automatically.
What actually occur: I found the connection error exception caused by keep alive will also get into the onError logic, and the client will exit.
My question is, whether the expectation I proposed is resonable and why? If it is resonable, how can I enable retry when code get into onError logic? If it is not resonable, how I understand the relationship between onError and retry? Why I should not retry when occur onError?