Giter VIP home page Giter VIP logo

cheetrpc's Introduction

  • CheetRpc

  • 基于netty实现的一个简易rpc 框架,会陆续完成 主要是用来学习netty

  • 增加服务端心跳检测

  • 超时链接将被关闭

  • ser.Heartbeat(1,1,1);

  • 使用 服务端

public class RpcImpl{


    public int GetRandom(int a,int b){
      return   a-b;
    }

    public int Add(int a, int b) {
        return a+b;
    }
}

public class Server {
    public static void main(String[] args) {
        CheetRpcServer ser=new CheetRpcServerImpl();
        ser.Rigist(RpcImpl.class);

        ser.ListenServer(8080);
    }
}

客户端

  • 单机模式

CheetRpcClientImpl client=new CheetRpcClientImpl();

     
        client.SetDiscovery(new StandaloneDiscovery("ip",port));


        Object call = client.Call(".RpcImpl","GetRandom", 1, 2);

        System.out.println(call.toString());

         call = client.Call(".RpcImpl","Add", 1, 2);

        System.out.println(call.toString());


        call = client.Call(".RpcImpl","Add", 1, 2);

        System.out.println(call.toString());
  • zookeeper 多主机模式

    • 我们可以启动多个服务端
    • 但是前提需要手动写入节点到zookeeper 中
    • 列如 /rpc_zk/127.0.0.1:8080 、/rpc_zk/127.0.0.1:8081
    • 我们分别启动8080 服务和8081 服务
         CheetRpcClientImpl client=new CheetRpcClientImpl();
    
        //load () 选择负载均衡算法
        ZookeeperConfig rpc_zk = ZookeeperConfig.builder().load(new Pollingbalancing())
                .ServerNode("/rpc_zk")
                .zkAddr("127.0.0.1:9000").build();
    
        client.SetDiscovery(new ZookeeperDisovery(rpc_zk));
    
    
        Object call = client.Call(".RpcImpl","GetRandom", 1, 2);
    
        System.out.println(call.toString());
    
         call = client.Call(".RpcImpl","Add", 1, 2);
    
        System.out.println(call.toString());
    
    
        call = client.Call(".RpcImpl","Add", 1, 2);
    
        System.out.println(call.toString());

cheetrpc's People

Contributors

adminoryuan avatar fanyuansheng 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.