Giter VIP home page Giter VIP logo

rex_rpc's Introduction

rex_rpc

a lightweight rpc framework demo based on netty, zookeeper, spring

一个基于Netty,Zookeeper,Spring的一个轻量级框架。

参考 轻量级分布式 RPC 框架

设计

rpc

模块组成

  1. rpc-common:通用工具包
  2. rpc-registry: 注册中心接口
  3. rpc-registry-zookeeper: 注册中心Zookeeper实现
  4. rpc-server: 生产者服务端
  5. rpc-client: 消费者客户端

案例

  1. 定义生产者接口(rpc-sample-api)

    public interface HelloService {
    
        String hello(String name);
    
        String hello(Person person);
    }
  2. 生产者实现(rpc-sample-server)

    // 该注解标志这是一个生产者的接口实现
    @RpcService(HelloService.class)
    public class HelloServiceImpl implements HelloService{
        @Override
        public String hello(String name) {
            return "hello! " + name;
        }
    
        @Override
        public String hello(Person person) {
            return "Hello! " + person.getFirstName() + " " + person.getLastName();
        }
    }
    
    // 启动类
    public class RpcBootstrap {
        public static void main(String[] args) {
            log.debug("start server");
            new ClassPathXmlApplicationContext("spring.xml");
        }
    }
  3. 消费者实现(rpc-sample-client)

    public class HelloClient {
        public static void main(String[] args) {
            ApplicationContext context = new ClassPathXmlApplicationContext("spring.xml");
            RpcProxy rpcProxy = context.getBean(RpcProxy.class);
            HelloService helloService = rpcProxy.create(HelloService.class);
            String result = helloService.hello("world");
            System.out.println(result);
        }
    }

rex_rpc's People

Contributors

todorex avatar

Stargazers

 avatar  avatar

Watchers

 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.