Giter Club home page Giter Club logo

my-rpc's Introduction

My-RPC

  • 支持多种注册中心(包括Zk和Nacos)
  • 支持Java序列化和protobuf序列化以及Hessian序列化协议
  • 支持多种客户端负载均衡(随机、轮询、加权轮询和平滑加权轮询)算法

食用不完全指北

1.clone代码到本地

git clone [email protected]:Anti-Warlock/My-RPC.git

2.打包到本地maven仓库

mvn clean install -Dmaven.test.skip=true

3.引入maven坐标

        <dependency>
            <groupId>org.example</groupId>
            <artifactId>My-RPC</artifactId>
            <version>1.0-SNAPSHOT</version>
        </dependency>

##客户端 使用@RpcClient注入远程方法

@RestController
@RequestMapping("test")
public class TestController {

    @RpcClient
    private UserService userService;

    @GetMapping("/user")
    public ApiResult<User> getUser(@RequestParam("id")Long id){
        ApiResult<User> user = userService.getUser(id);
        return user;
    }
}

配置项:

属性 含义 可选项
anti.rpc.protocol 消息序列化协议 java,protobuf,hessian
anti.rpc.register-type 注册中心类型 zk,nacos
anti.rpc.address 注册中心地址 默认localhost:2181
anti.rpc.load-balance 负载均衡算法 random
round
weightRound
smoothWeightRound

##服务端 提供远程方法

@RpcServer
public class UserServiceImpl implements UserService{

    private static  Logger logger = LoggerFactory.getLogger(UserService.class);


    @Override
    public ApiResult<User> getUser(Long id) {
        logger.info("现在是【A】机器提供服务");
        User user = new User(1L,"XX",2,"www.aa.com");
        return ApiResult.success(user);
    }
}

配置项:

属性 含义 可选项
anti.rpc.protocol 消息序列化协议 java,protobuf,hessian
anti.rpc.register-type 注册中心类型 zk,nacos
anti.rpc.address 注册中心地址 默认localhost:2181
anti.rpc.server-port 服务端端口 自定义,不冲突即可
anti.rpc.load-balance 负载均衡算法 random
round
weightRound
smoothWeightRound
anti.rpc.weight 当前服务所占权重 自定义

##性能测试篇

  • 测试环境: wsl Ubuntu-20.04
  • 测试步骤:
    1.本地启动zk:
   zkServer.sh start 

2.启动三个服务端和一个客户端,平滑加权轮询算法: Image text
3.使用ab进行压力测试,4个线程发送10000个请求:

    ab -c 4 -n 1000 http://localhost:8081/test/user?id=1

Image text

my-rpc's People

Contributors

anti-warlock avatar neucoder avatar

Watchers

 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.