Code Monkey home page Code Monkey logo

fuck-rpc's Introduction

RPC 的简单实现

基于 netty4 实现的一个简单的 RPC , 代码精简. just for learn.

如何运行

  • 安装 lombok
  • 安装 zookeeper
  • 相继运行 fuck-test 项目下的 ProviderDemo ConsumerDemo 即可查看实现结果

同步和异步

tcp本身的双向通信是异步的,netty支持的nio底层也是异步。

  • 同步:线程阻塞, wait(timeout),等待provider相应返回,解除线程的阻塞,返回给biz线程.
  • 异步:线程不阻塞,支持返回,利用java8的 CompletableFuture 实现,可参见测试代码.

Netty

  • 每一个channel都有一个pipeline. Pipeline <=====> channel
  • 每一个channel都会有多个channelHandler,这些handler在channel初始化的时候设置上去
  • 每一个handler都有一个context. handler <====> context //一个handler就和一个绑定起来了
  • 每一个pipeline都会将自己的channel的handler(上下文) channelHandlerContext串联成链表,head和tail由netty分配
  • 每一个channel都会分配到一个NioEventLoop上,这个eventLopp可以netty传递进行的,也可以是netty自己的 (每一个NioEventloop都是单线程的)

Note: channel 不和 NioEventLoop 进行绑定(但是实际上是有这个关系的),这个关系由 pipeline 维系

fuck-rpc's People

Stargazers

hpulzl avatar

Watchers

James Cloos 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.