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.

RSocket LoadBalancing does not seem to work with Spring Boot.

See original GitHub issue

Hi @OlegDokuka

I was looking at this example and it works just fine.

https://github.com/rsocket/rsocket-java/blob/master/rsocket-examples/src/main/java/io/rsocket/examples/transport/tcp/loadbalancer/RoundRobinRSocketLoadbalancerExample.java

I was trying to implement this with Spring Boot. However it seems to always use the first instance it connects to.

I have a project here. I also have provided the steps as part of README https://github.com/vinsguru/rsocket-load-balancing

Server-App:

  • Navigate to server-app cd server-app
  • Build the jar mvn clean package
  • Run 2 instances of this app as shown below.
java -jar -Dspring.rsocket.server.port=6565 target/server-app-0.0.1-SNAPSHOT.jar
java -jar -Dspring.rsocket.server.port=6566 target/server-app-0.0.1-SNAPSHOT.jar

Client-app

  • application.yaml - by default uses the above server instance details - localhost:6565 and localhost:6566

  • Runt the main application.

  • Check the server console output. Only one of the instance is processing all the requests!!

Does it require any other config?

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
OlegDokukacommented, Jan 26, 2021

@vinsguru the problem is still in configuration

private List<LoadbalanceTarget> toLoadBalanceTarget(List<RSocketServer> rSocketServers){
        System.out.println(rSocketServers);
        return rSocketServers.stream()
                .map(server -> LoadbalanceTarget.from(server.getHost() + server.getPort(), TcpClientTransport.create(server.getHost(), server.getPort())))
                .collect(Collectors.toList());
    }

As it was mentioned in the stackoverflow answer, the LoadbalanceTarget has 1 important parameter which is key using key the RSocketPool is capable of making difference between given targets and identify which target is new and which has already been there. In your setup, you always use the localhost as a key, hence for RSocketPool all the new LoadbalancerTargets seemed to be the same as before, and therefore you observed traffic to only a single target.

Also, please note, that if one of the targets disappears, your connection will be immediately disposed (that is something that we have to improve) which means if the connection is still alive and has ongoing traffic, that traffic will be immediately interrupted and your request will be signaled with onError. To fix that, I suggest putting extra retry logic. For example:

    @Override
    public void run(String... args) throws Exception {
        Flux.range(1, 10000)
            .delayElements(Duration.ofMillis(10))
            .flatMap(i -> rSocketRequester.route("square-calculator").data(i).retrieveMono(Integer.class).retry())
            .doOnNext(i -> System.out.println("Response : " + i))
            .blockLast();
    }
0reactions
OlegDokukacommented, Jan 26, 2021

You are welcome @vinsguru. And no worries!

Read more comments on GitHub >

github_iconTop Results From Across the Web

spring boot - rsocket - how to balance the load - Stack Overflow
1 Answer 1 ... There are two options for this: use low-level load balancer on client side from rsocket-load-balancer; deploy RSocket broker ...
Read more >
RSocket Load Balancing - Client Side - Vinsguru
Learn Spring RSocket Load Balancing from client side to distribute the rsocket requests among multiple servers.
Read more >
Getting Started With RSocket: Spring Boot Server
Step 3: Start The Spring Boot RSocket Server​​ Alternatively, you can use the “Build” and “Run” commands in your Java IDE if you...
Read more >
the Reactive Revolution:RSocket and Spring Cloud Gateway
Spring is adding support for RSocket, it's coming in Spring 5.2. There's already been one or two milestones of framework, Spring Boot will...
Read more >
Communication With RSocket – Abstraction Over ... - Grape Up
The second available solution, which provides an abstraction over the RSocket is the integration with Spring Boot. Here we use RSocket as a...
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