1

I have the following program through which I can detect the connection failure i.e doBeforeRetry.

Can someone tell me how to detect the successful connection or reconnection. I want to integrate a Health Check program that monitors this connection, but I am unable to capture the event that informs the connections is successfull.

Thanks

 requester =  RSocketRequester.builder()
                .rsocketConnector(connector -> {
                    connector.reconnect(Retry
                            .fixedDelay(Integer.MAX_VALUE,Duration.ofSeconds(1))
                            .doBeforeRetry(e-> System.out.println("doBeforeRetry===>"+e))
                            .doAfterRetry(e-> System.out.println("doAfterRetry===>"+e))
                    );
                    connector.payloadDecoder(PayloadDecoder.ZERO_COPY);
                }
                ).dataMimeType(MediaType.APPLICATION_CBOR)
                .rsocketStrategies(strategies)
                .tcp("localhost", 7999);
Saji
  • 111
  • 6

2 Answers2

2

I achieved the detection of successful connection or reconnection with the following approach.

Client Side (Connection initialization)

   Mono<RSocketRequester> requester =  Mono.just(RSocketRequester.builder()
                 .rsocketConnector(
                   // connector configuration goes here
                 )
                .dataMimeType(MediaType.APPLICATION_CBOR)
                .setupRoute("client-handshake") 
                .setupData("caller-name")
                .tcp("localhost", 7999)));

One the server side

    @ConnectMapping("client-handshake")
    public void connect(RSocketRequester requester, @Payload String callerName) {
        LOG.info("Client Connection Handshake: [{}]", callerName);
        requester
        .route("server-handshake")
        .data("I am server")
        .retrieveMono(Void.class)
        .subscribe();
    }

On the client side, when I receive the callback on the below method, I detect the connection is successfull.

   @MessageMapping("server-handshake")
    public Mono<ConsumerPreference> handshake(final String response){
            LOG.info("Server Connection Handshake received : Server message [{}]", response.getCallerName());
            connectionSuccess.set(true);
            return Mono.empty();
        }else{
            throw new InitializationException("Invalid response message received from Server");
        }
    }

Additionally, created a application level heartbeat to ensure, the liveliness of the connection.

Saji
  • 111
  • 6
0

If you want to know if it's actually healthy, you should probably have a side task that is polling the health of the RSocket, by sending something like a custom ping protocol to your backend. You could time that and confirm that you have a healthy connection, record latencies and success/failures.

Yuri Schimke
  • 12,435
  • 3
  • 35
  • 69
  • Understood. But if there are handlers for notifying connection drops and errors i.e doOnError, doOnTermination etc, why cannot we have method to notify a successful connection ? what is the limitation ? I have implemented a solution similar to the one you have suggested i.e a polling mechanism with Server on a regular interval to see if am getting the response back, thus, certifying the connection is good. Which I think is so clean. – Saji Dec 18 '20 at 10:21
  • 100% agree. I think at the moment that will require a PR to expose this particular event, the successful reconnect in an observable way. It might be possible and I'm just unaware of how, so probably worth raising a feature request on https://github.com/rsocket/rsocket-java – Yuri Schimke Dec 18 '20 at 10:24
  • Thanks Yuri for your response. I have created an enhancement issue with rsocket-java. https://github.com/rsocket/rsocket-java/issues/965 – Saji Dec 18 '20 at 12:35