GithubHelp home page GithubHelp logo

hsldegit / rpc-demo-1 Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ganchaoyang/rpc-demo

1.0 1.0 0.0 21 KB

微服务中RPC协议起到了至关重要的作用,我们常用的Dubbo就是基于RPC协议的远程服务调用框架。那么Dubbo已经很成熟了,本项目只是作为研究RPC的一个小小的demo。

Java 100.00%

rpc-demo-1's Introduction

简介

微服务近几年已经发展的炉火纯青了,那么在微服务中RPC协议起到了至关重要的作用。我们常用的Dubbo就是基于RPC协议的远程服务调用框架。那么Dubbo已经很成熟了,本项目只是作为研究RPC的一个小小的demo。

结构

  • consumer - 消费者程序
  • provider - 服务提供者程序
  • rpc-api - 所有远程服务接口的api,应该同时被consumer和provider依赖
  • core - rpc框架的核心代码

具体实现

结构图

  • zookeeper - 注册中心,记录服务提供者的地址、名称等信息。
  • provider - 服务提供者
  • consumer - 消费者
  • rpc server - 会随服务提供者一起启动,顺带会启动一个netty服务器接受远程客户端的调用信息
  • rpc client - 发生远程调用时,rpc server创建连接并进行通信,实现远程调用的效果

Provider的启动

  1. provider启动时,会随之启动rpc server
  2. 扫描provider中所有有@RpcService注解的类并交由BeanFactory管理
  3. 启动一个netty server,最后向注册中心注册提供者信息。

Consumer的启动

  1. consumer启动时,rpc框架会自动扫描consumer中所有有@RpcConsumer注解的属性
  2. 并且自动注入其远端的代理

调用过程

  1. 发生远程调用操作时,代理会通过netty客户端向对应netty服务器发送调用信息,包含类,方法名,参数,参数类型信息
  2. provider所启动的netty服务器收到调用信息,通过反射调用具体的方法,并返回结果给netty客户端
  3. netty客户端收到返回结果,并返回给consumer,完成整个调用过程。

rpc-demo-1's People

Stargazers

 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.