# 分布式远端调用框架 **Repository Path**: zfox-f/rpc-framework-implementation ## Basic Information - **Project Name**: 分布式远端调用框架 - **Description**: 本项目是基于 C++、JsonCpp、muduo ⽹络库 实现⼀个简单、易⽤的 RPC 通信框架,即使是不懂⽹络的开发者也可以很快速的上⼿,它实现了同步调⽤、异步callback调⽤、异步futrue调⽤、服务注册 / 发现,服务上线 / 下线 以及 发布订阅 等功能设计 - **Primary Language**: C++ - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 6 - **Forks**: 1 - **Created**: 2025-03-04 - **Last Updated**: 2025-04-08 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # RPC框架实现 ## 介绍 本项目是基于 C++、JsonCpp、muduo ⽹络库 实现⼀个简单、易⽤的 RPC 通信框架,即使是不懂⽹络的开发者也可以很快速的上⼿,它实现了同步调⽤、异步callback调⽤、异步futrue调⽤、服务注册 / 发现,服务上线 / 下线 以及 发布订阅 等功能设计 ## 软件架构 - 框架设计:框架分三层进行设计 -- (抽象层,实现层,业务层) - 抽象:针对底层的网络通信和协议部分进行了抽象,降低框架的依赖,提高框架的灵活度,以及可维护性 - 实现:针对抽象的功能进行具体的实现(muduo库搭建高性能客户端服务器,TLV应用层协议格式,消息类型) - 业务:基础rpc,服务发现与注册以及上线/下线通知,发布订阅。 ## 安装教程 Ubuntu-22.04环境搭建 ⬇️ 安装 `wget` (⼀般情况下默认会⾃带) ```cpp $ sudo apt-get install wget ``` 🪞 更换国内软件源 先备份原来的 `/etc/apt/source.list` ⽂件 ```cpp $ sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak ``` 🆕 添加软件源⽂件内容,新增以下内容 ```cpp deb http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse #添加清华源 deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal main restricted universe multiverse deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates main restricted universe multiverse deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-backports main restricted universe multiverse ``` 新增完毕后,更新源 ```cpp $ sudo apt-get update ``` ⬇️ 安装 `lrzsz` 传输⼯具 ```cpp $ sudo apt-get install lrzsz ``` ⬇️ 安装编译器 `gcc/g++` ```cpp $ sudo apt-get install gcc g++ ``` ⬇️ 安装项⽬构建⼯具 `make` ```cpp $ sudo apt-get install make ``` ⬇️ 安装调试器 `gdb` ```cpp $ sudo apt-get install gdb ``` ⬇️ 安装 `git` ```cpp $ sudo apt-get install git ``` ⬇️ 安装 `cmake` ```cpp sudo apt-get install cmake ``` ⬇️ 安装 `jsoncpp` ```cpp $ sudo apt-get install libjsoncpp-dev ``` ⬇️ 安装 `Muduo` - 下载源码 ```cpp # git⽅式 $ git clone https://github.com/chenshuo/muduo.git ``` 👝 **下载不了的也可以使用博主的 gitee下载 zip文件** ```cpp git clone https://gitee.com/zfox-f/rpc-framework-implementation.git ``` 然后把 `build` 删掉,这里是已经安装出来的信息,然后进入 `third` 解压和运⾏脚本编译安装 ```cpp unzip muduo-master.zip ./build.sh ./build.sh install ``` - ⬇️ 安装依赖环境 ```cpp $ sudo apt-get install libz-dev libboost-all-dev ``` 💻 注意:这里有些人可能会出现这个问题 ![输入图片说明](rpc/image/3131743136125_.pic.jpg) 原因是 Linux版本为(Ubuntu-22.04)以上, 需要切换回 20.04 > **这个问题就是应该你当前的系统中内置了 python3.10,而 boost 库 下载需要使用到 python3.9,所以出现这个问题,由于是内置的 python 版本,所以无法删除,导致这个问题目前只能是切换操作系统为 ubuntu20.04 才能够解决** ☁️ 运⾏脚本编译安装 ```cpp $ unzip muduo-master.zip $ ./build.sh $ ./build.sh install ``` ## 使用说明 本人项目讲解博客 [https://blog.csdn.net/weixin_50776420/article/details/145968628?spm=1001.2014.3001.5501) ## 参与贡献 1. Fork 本仓库 2. 新建 Feat_xxx 分支 3. 提交代码 4. 新建 Pull Request ## 扩展 - 实现负载上报系统 - 扩展负载均衡算法 - 源地址hash算法 - 轮询算法 - 随机算法 - 根据上报系统中服务的负载决定 - 扩展发布订阅的转发策略 - 实现服务⼼跳检查,超时管理 ## 参考 - https://zhuanlan.zhihu.com/p/460646015 - https://zhuanlan.zhihu.com/p/33298916 - https://zhuanlan.zhihu.com/p/388848964 - 源码:https://github.com/cinemast/libjson-rpc-cpp - 源码:https://github.com/qicosmos/rest_rpc