Giter Site home page Giter Site logo

rsocket-load-balancing's Introduction

RSocket Load Balancing with Spring Cloud Registry

RSocket load balance based on Spring Cloud Service Registry.

LoadBalance Structure

How to run?

  • Start Consul first: docker-compose up -d consul or consul agent -dev ,then open http://localhost:8500
  • Build the project: mvn -DskipTests clean package
  • Start server-app: java -jar server-app/target/server-app-1.0.0-SNAPSHOT.jar
  • Start client-app: java -jar client-app/target/client-app-1.0.0-SNAPSHOT.jar
  • Test your RSocket service invocation: curl http://localhost:9080/square/3

App & Service interface naming specification

Spring Cloud Service Registry uses spring.application.name as service name on registry server, and appName is the serviceId argument in ReactiveDiscoveryClient.getInstances(String serviceId);

For example, we have a service app with two service interfaces: MathCalculatorService and ExchangeCalculatorService.
Please use Java package naming style to name your app, such as com-example-calculator. Service interface naming should follow String serviceName = appName.replace("-", ".") + "." + interfaceName; rule, example as following:

  • com.example.calculator.MathCalculatorService
  • com.example.calculator.ExchangeCalculatorService

If you use RSocket Broker to proxy the requests, and you should use broker: as prefix for service name, such as broker:com.example.calculator.ExchangeCalculatorService, and broker is the RSocket Broker's name, and you can use ReactiveDiscoveryClient.getInstances(appName) to query broker instance list.

Why this naming style? Take a look at the following steps to call remote RSocket services:

  • Extract appName from service full name. For example, appName is com-example-calculator from com.example.calculator.MathCalculatorService
  • Invoke ReactiveDiscoveryClient.getInstances(appName) to get app instance list
  • Build RSocketRequester with load balance support with RSocketRequester.Builder.transports(servers)
  • Call RSocketRequester api with service full name as routing key
 rsocketRequester.route("com.example.calculator.MathCalculatorService.square")
                .data(number)
                .retrieveMono(Integer.class)

This naming style is easy for RSocket to interact with service registry and RSocket service routing.

If you can not inline the appName in service's full name, and you can use appName as schema style for service invocation,
such as calculator-server:com.example.calculator.math.MathCalculatorService. With this way,
and it's easy to migrate other applications into RSocket RPC design.

References

rsocket-load-balancing's People

Contributors

linux-china avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.