question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Reconnect after server restart

See original GitHub issue

Dear RSocket team,

First of all, I am playing with rsocket. It looks great so far. This is more of a question. This is a very simple spring boot service class for rsocket client. As you see we establish rsocket connection as part of constructor, cache the requestorMono. The below code works perfectly fine as long as server is not restarted. When you restart server, the connection is broken. Client needs to be restarted to make this work. The retry in the ping chain will NOT help as it is cached already. Is there any built in approach in rsocket to handle this?

@Service
public class RSocketPingService {

    private final Mono<RSocketRequester> requesterMono;

    // Spring Boot is creating an auto-configured RSocketRequester.Builder bean
    public RSocketPingService(RSocketRequester.Builder builder) {
        this.requesterMono = builder
                .dataMimeType(MediaType.APPLICATION_CBOR)
                .connectTcp("localhost", 7000).retry(5).cache();
    }

    public Mono<String> ping() {
        return this.requesterMono.flatMap(requester -> requester.route("pong")
                .data("TEST")
                .retrieveMono(String.class));
    }

}

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:10 (3 by maintainers)

github_iconTop GitHub Comments

7reactions
OlegDokukacommented, Jul 31, 2020

Hello @uselvvi!

It is great to get more users on board!

Have you looked at build-in reconnect feature which does exactly what you need:


@Service
public class RSocketPingService {

    private final Mono<RSocketRequester> requesterMono;

    // Spring Boot is creating an auto-configured RSocketRequester.Builder bean
    public RSocketPingService(RSocketRequester.Builder builder) {
        this.requesterMono = builder
                .rsocketConnector(connector -> connector.reconnect(Retry.backoff(10, Duration.ofMillis(500)))
                .dataMimeType(MediaType.APPLICATION_CBOR)
                .connectTcp("localhost", 7000);
    }

    public Mono<String> ping() {
        return this.requesterMono.flatMap(requester -> requester.route("pong")
                .data("TEST")
                .retrieveMono(String.class));
    }

}

2reactions
vinsgurucommented, Jan 8, 2021

@nbabic298 I just checked the SO answer as well. It seems to match with what I have in this repo as well. Check your version. I use 2.3.2.RELEASE.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to reconnect to a socket after server restart - Stack Overflow
Just reconnect from the client. But if you have multiple fail-over servers you wouldn't want to reconnect to the one that just failed,...
Read more >
Restore connection after server restart | OPC UA Standard
I tried session.Reconnect() but it throw BadSessionIdInvalid exception. And i tried session.Recreate(session) , in this case ServerState becomes ...
Read more >
OpenVPN reconnect after server restart
I have an OpenVPN server and some clients which only have access through the VPN. Sometimes, I need to restart my OpenVPN server....
Read more >
Client reconnecting after server restarts - MSDN - Microsoft
When a server goes offline -- it reboots, fails, the app domain recycles, etc. -- the result might be similar to a lost...
Read more >
Client won't reconnect until server restarted. : r/WireGuard
After the client reboot the last handshake was the moment before reboot. I waited until it was about ten minutes. Last handshake on...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found