Preface

RPC The frame is the knowledge point that the back-end siege lion can never get around , At present, some well-known in the industry are DubboSpring Cloud etc. . Many people are stuck in the stage of only using , As a program ape , Have curiosity and study deeply , In order to effectively improve their competitiveness . Students on the next floor , Will go through the source code , See how the function is implemented , This is a good start . Look at the source code, it's easy to forget after a period of time , I think after reading the source code , It's better to develop one yourself , In this way, you will have a deeper understanding of the framework . In my submission ," Will use "、" Can read the source code "、" Will write it out " It's a completely different level .

This series " Of the wheel series RPC", Teach everyone how to build their own RPC frame .

The following is a simple version RPC Source code , welcome Star、Fork. Level co., LTD. , You have better ideas to put forward .

Github:https://github.com/chenchuxin/ccx-rpc

Gitee:https://gitee.com/imccx/ccx-rpc

RPC Structure of framework

One of the simplest RPC The framework is divided into three parts : Registry Center 、 Server side 、 client . The following is the simplest structure flow chart .



Part of the :

  1. Registry Center : Used to register and obtain services .
  2. Server side : Means the party providing the service , Also called service provider Provider
  3. client : Refers to the party calling the service , Also called service consumer Consumer

technological process :

  1. The server registers the service information in the registry , It usually contains the server address 、 Interface classes and methods
  2. The client obtains the information of the corresponding service from the registry
  3. According to the information of the service , Call the interface to the server through the network

RPC Frame design

Many details of the above process are not drawn , for example :

  1. In what form does the server register with the registry ?
  2. How does the client call the service like an interface ?
  3. What is the network protocol for invoking the service ?

A basic RPC frame , It needs to include the following parts :

  1. Registry Center : The registration center is responsible for the registration and search of service information . When the server starts , Scan all services , Then register your service address and service name in the registry . Before the client invokes the service , Find the address of the service through the registry , You can call the service through the address of the service . Common registries are ZookeeperEureka etc. .
  2. A dynamic proxy : Client call interface , The framework needs to be able to call services remotely according to the interface , This step is not perceived by the user . thus , You need to use dynamic agents , User call interface , It's actually calling the dynamically generated proxy class . Common dynamic agents are :JDK Proxy,CGLib,Javassist etc. .
  3. Network transmission :RPC A remote call is actually a network transfer , So network transmission is RPC An essential part of the framework . The network framework has Java NIONetty Frame, etc .
  4. Custom protocol : Network transmission needs to formulate a good protocol , A good protocol can improve the efficiency of transmission .
  5. serialize : Network transmission will certainly involve serialization , Common serialization methods are JsonProtostuffKyro etc. .
  6. Load balancing : When the number of requests is large , You need to increase the number of servers , Once added , It will involve the choice of services , This is load balancing . Common load balancing strategies are : polling 、 Random 、 Weighted polling 、 Weighted random 、 Consistent hashes and so on .
  7. Cluster fault tolerance : When the request service is abnormal , Should we report the error directly ? Try again ? Or ask for other services ? This is the cluster fault tolerance strategy .
  8. ....

The above design , The code implementation will be introduced in detail in the next article .

Of the wheel series RPC 1: How to develop from scratch RPC More articles on Framework

  1. Repeat wheel series —— be based on Ocelot A gateway similar to the Alipay interface mode

    Repeat wheel series —— be based on Ocelot A gateway similar to the Alipay interface mode introduction Repeating wheel series is my usual summary . Some wheels are based on wheels provided by the community , Here, I'd like to share some interesting information about the use process . There are some ideas or methods in this field ...

  2. Repeat wheel series —— be based on FastReport Design the printing template to realize the desktop WPF Set printing and Shangchao POS Highly adaptive small ticket printing

    Repeat wheel series —— be based on FastReport Design the printing template to realize the desktop WPF Set printing and Shangchao POS Highly adaptive small ticket printing One . introduction Desktop systems often need to interface with various hardware devices , Like a scanner . Card reader . Printers, etc . Here is the next desktop ...

  3. Self made wheel series OOM frame AutoMapper

    [ Preface ] OOM The frame must be there Web It's very frequently used in development , If you don't know much about it OOM frame , So we're right OOM Let's talk about the framework . OOM seeing the name of a thing one thinks of its function ,Object-Object-Mapping Between entities . common ...

  4. Make wheel series ( 3、 ... and ): A simple and fast html Virtual syntax tree (AST) Parser

    Preface Virtual syntax tree (Abstract Syntax Tree, AST) It's an interpreter / The compiler is the basis of syntax analysis , It is also the basic tool of many front-end compilation tools , such as webpack, postcss, less etc. . about ...

  5. Repeat wheel series --dijkstra Algorithm

    I had a brain fever the year before last ( The ideal is full , Reality is thin ), Wrote this inefficient version of shortest path first , And keep memories . spf.h #ifndef SPF_H_ #define SPF_H_ typedef struct { int ...

  6. Repeat wheel series -- Memory pool (C Language )

    This code is the memory management of my last company work project ( Based on partner algorithm ) A simplified and simplified version of . Because there is no memory boundary check : Because there is no memory usage statistics : Because thread safety is not considered : Because there is no specific file location information for memory allocation operation : because ...

  7. Repeat wheel series -- string manipulation (C Language )

    These character codes were written before , From a long, long time ago VC++ project , In the Department programming competition at that time, because the project code was used xsplit function , Never in my wildest dreams , There are pits in the project that has been done for several years ..xsplit Functions can't split even ...

  8. Learn to make wheels together ( Two ): Write one from scratch Redux

    This article is the second in a series on building wheels , In this article, we will write a small and complete... From scratch Redux, This series of articles will select some front-end classic wheel for source code analysis , And gradually from scratch , This series will learn about Promises/A+,Red ...

  9. Learn to make wheels together ( One ): Write a match from scratch Promises/A+ canonical promise

    This article is the first in a series on building wheels , In this article, we will start from scratch to write an article that conforms to Promises/A+ canonical promise, This series of articles will select some front-end classic wheel for source code analysis , And gradually from scratch , This series will learn about Pr ...

  10. Learn to make wheels together ( 3、 ... and ): Write one from scratch React-Redux

    This is the third in a series of learning how to make wheels , In this article, we will start from scratch to write a React-Redux, This series of articles will select some front-end classic wheel for source code analysis , And gradually from scratch , This series will learn about Promises/A+,Re ...

Random recommendation

  1. HTML Code shorthand :Emmet and Haml

    http://www.ruanyifeng.com/blog/2013/06/emmet_and_haml.html?bsh_bid=657901854 HTML Code shorthand :Emmet and Haml   ...

  2. win7 build ios development environment

    Refer to the article for the installation process : http://jingyan.baidu.com/article/ff411625b9011212e48237b4.html http://www.loukit.com/threa ...

  3. About all kinds of things on the Internet mysql Performance test conclusion

    About all kinds of performance test posts on the Internet , I would like to make the following points : 1. In order to make the performance test more objective . actual , What scenarios should be tested for , Inquire about . Or modify , Whether the primary key is included , Contains several indexes , What's the difference between them . Because it's different mysql branch ...

  4. Java Processing of time and date

    1. Get the current system time and date and format the output import java.util.Date; import java.text.SimpleDateFormat; public class NowStrin ...

  5. C++ Split string -copy()

    c++ Split string method : #include <iostream>#include <string>#include <sstream>#include <alg ...

  6. java review 003

    Today we will mainly review the data structure Trees Self-balancing binary search tree AVL Trees ( High balanced tree )(wiki) characteristic : The maximum height difference between two subtrees of any node is one Time complexity : lookup . Insert and delete are... On average and at worst O(log n) red ...

  7. Codeforces Round #330 (Div. 2)D. Max and Bike Two points Physics

    D. Max and Bike Time Limit: 20 Sec Memory Limit: 256 MB Topic linking http://codeforces.com/contest/595/probl ...

  8. 1187: [HNOI2007] Magic amusement park - BZOJ

    Description After a hard journey , The hero is small P Return by airship . On the way back , Small P Found in the boundless desert , There is a long and narrow green space, which is particularly conspicuous . Take a closer look down , Only to find that this is an amusement park , Designed for people who are tired during the journey . ...

  9. codeforces 463E . Caisa and Tree

    Topic link Give a tree , Two kinds of operations , One is to point u The weight of is changed to y, The other is to query the root node to point u On the way , gcd(v, u)>1 The deepest point v. The modification operation shall not exceed 50 Time . This question , Violence can lead to , But in ...

  10. 【Aladdin Unity3D Shader Programming 】 One of Basic entry

    OpenGL.DirectX as well as GLSL.HLSL.CG OpenGL and DirectX It's the image API , For rendering 2D or 3D graphics . GLSL Coloring language is used in OpenGL Color programming language in , It's a little bit flat ...