{"id":18600576,"url":"https://github.com/houbb/rpc","last_synced_at":"2025-04-10T18:31:25.593Z","repository":{"id":44828354,"uuid":"212915479","full_name":"houbb/rpc","owner":"houbb","description":"Java rpc framework based on netty4.（java 手写 dubbo rpc 框架）","archived":false,"fork":false,"pushed_at":"2022-11-30T04:43:54.000Z","size":463,"stargazers_count":111,"open_issues_count":4,"forks_count":28,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-04T01:02:09.285Z","etag":null,"topics":["aio","awesome","awesome-java","dubbo","dubbo3","grpc","handwrite","java-network","netty","netty4","nio","rpc"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/houbb.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-10-04T23:02:11.000Z","updated_at":"2025-03-17T16:45:45.000Z","dependencies_parsed_at":"2023-01-23T05:46:26.367Z","dependency_job_id":null,"html_url":"https://github.com/houbb/rpc","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/houbb%2Frpc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/houbb%2Frpc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/houbb%2Frpc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/houbb%2Frpc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/houbb","download_url":"https://codeload.github.com/houbb/rpc/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248207057,"owners_count":21065191,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["aio","awesome","awesome-java","dubbo","dubbo3","grpc","handwrite","java-network","netty","netty4","nio","rpc"],"created_at":"2024-11-07T02:04:29.559Z","updated_at":"2025-04-10T18:31:25.565Z","avatar_url":"https://github.com/houbb.png","language":"Java","funding_links":[],"categories":["开发框架"],"sub_categories":["RPC框架"],"readme":"# rpc\n\n[rpc](https://github.com/houbb/rpc) 是基于 netty 实现的 java rpc 框架，类似于 dubbo。\n\n[![Build Status](https://travis-ci.com/houbb/rpc.svg?branch=master)](https://travis-ci.com/houbb/rpc)\n[![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.github.houbb/rpc/badge.svg)](http://mvnrepository.com/artifact/com.github.houbb/rpc)\n[![](https://img.shields.io/badge/license-Apache2-FF0080.svg)](https://github.com/houbb/rpc/blob/master/LICENSE.txt)\n[![Open Source Love](https://badges.frapsoft.com/os/v2/open-source.svg?v=103)](https://github.com/houbb/nlp-common)\n\n\u003e [变更日志](https://github.com/houbb/rpc/blob/master/CHANGELOG.md)\n\n主要用于个人学习，由渐入深，理解 rpc 的底层实现原理。\n\n## 特性\n\n- 基于 netty4 的客户端调用服务端\n\n- p2p 调用\n\n- serial 序列化支持\n\n- timeout 超时处理\n\n- register center 注册中心\n\n- load balance 负载均衡\n\n- callType 支持 oneway sync 等调用方式\n\n- fail 支持 failOver failFast 等失败处理策略\n\n- generic 支持泛化调用\n\n- gracefully 优雅关闭\n\n- rpcInterceptor 拦截器\n\n- filter 过滤器\n\n- check 客户端启动检测服务是否可用\n\n- heartbeat 服务端心跳\n\n# 快速入门\n\n## maven 引入\n\n```xml\n\u003cdependency\u003e\n    \u003cgroupId\u003ecom.github.houbb\u003c/groupId\u003e\n    \u003cartifactId\u003erpc-all\u003c/artifactId\u003e\n    \u003cversion\u003e${rpc.version}\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\nps: 如果本地 p2p 测试，register 注册中心可选。\n\n## 测试\n\n### 注册中心\n\n```java\nRegisterBs.newInstance().start();\n```\n\n### 服务端\n\n```java\nServiceBs.getInstance()\n         .register(ServiceIdConst.CALC, new CalculatorServiceImpl())\n         .registerCenter(ServiceIdConst.REGISTER_CENTER)\n         .expose();\n```\n\n### 客户端\n\n```java\n// 服务配置信息\nReferenceConfig\u003cCalculatorService\u003e config = ClientBs.newInstance();\nconfig.serviceId(ServiceIdConst.CALC);\nconfig.serviceInterface(CalculatorService.class);\n// 自动发现服务\nconfig.subscribe(true);\nconfig.registerCenter(ServiceIdConst.REGISTER_CENTER);\n// 拦截器测试\nconfig.rpcInterceptor(new CostTimeInterceptor());\n\nCalculatorService calculatorService = config.reference();\nCalculateRequest request = new CalculateRequest();\nrequest.setOne(10);\nrequest.setTwo(20);\n\nCalculateResponse response = calculatorService.sum(request);\nSystem.out.println(response);\n```\n\n# 前言\n\n工作至今，接触 rpc 框架已经有很长时间。\n\n但是对于其原理一直只是知道个大概，从来没有深入学习过。\n\n以前一直想写，但由于各种原因被耽搁。\n\n## 技术准备\n\n[Java 并发实战学习](https://houbb.github.io/2019/01/18/jcip-00-overview)\n\n[TCP/IP 协议学习笔记](https://houbb.github.io/2019/04/05/protocol-tcp-ip-01-overview-01)\n\n[Netty 权威指南学习](https://houbb.github.io/2019/05/10/netty-definitive-gudie-00-overview)\n\n这些技术的准备阶段，花费了比较长的时间。\n\n也建议想写 rpc 框架的有相关的知识储备。\n\n其他 rpc 框架使用的经验此处不再赘述。\n\n## 快速迭代\n\n原来一直想写 rpc，却不行动的原因就是想的太多，做的太少。\n\n想一下把全部写完，结果就是啥都没写。\n\n所以本次的开发，每个代码分支做的事情实际很少，只做一个功能点。\n\n陆陆续续经过近一个月的完善，对 rpc 框架有了自己的体会和进一步的认知。\n\n代码实现功能，主要参考 [Apache Dubbo](https://dubbo.apache.org/zh/docs/introduction/)\n\n# 文档\n\n## 文档\n\n文档将使用 markdown 文本的形式，补充 code 层面没有的东西。\n\n## 代码注释\n\n代码有详细的注释，便于阅读和后期维护。\n\n## 测试\n\n目前测试代码算不上完善。后续将陆续补全。\n\n# rpc 模块\n\n| 模块 | 说明 |\n|:---|:---|\n| rpc-common | 公共代码 |\n| rpc-register | 注册中心 |\n| rpc-server | 服务端 |\n| rpc-client | 客户端 |\n| rpc-all | 全部引用模块（简化包引用） |\n\n# 代码分支\n\n[release_0.0.1-server 服务端启动](https://github.com/houbb/rpc/tree/release_0.0.1)\n\n[release_0.0.2-client 客户端启动](https://github.com/houbb/rpc/tree/release_0.0.2)\n\n[release_0.0.3-客户端调用服务端](https://github.com/houbb/rpc/tree/release_0.0.3)\n\n[release_0.0.4-p2p 客户端主动调用服务端](https://github.com/houbb/rpc/tree/release_0.0.4)\n\n[release_0.0.5-serial 序列化](https://github.com/houbb/rpc/tree/release_0.0.5)\n\n[release_0.0.6-通用的反射调用](https://github.com/houbb/rpc/tree/release_0.0.6)\n\n[release_0.0.7-timeout 超时处理](https://github.com/houbb/rpc/tree/release_0.0.7)\n\n[release_0.0.8-register 注册中心](https://github.com/houbb/rpc/tree/release_0.0.8)\n\n[release_0.0.9-load balance 负载均衡](https://github.com/houbb/rpc/tree/release_0.0.9)\n\n[release_0.1.0-callType 调用方式](https://github.com/houbb/rpc/tree/release_0.1.0)\n\n[release_0.1.1-fail 失败策略](https://github.com/houbb/rpc/tree/release_0.1.1)\n\n[release_0.1.2-generic 泛化调用](https://github.com/houbb/rpc/tree/release_0.1.2)\n\n[release_0.1.3-gracefully 优雅关闭](https://github.com/houbb/rpc/tree/release_0.1.3)\n\n[release_0.1.4-rpcInterceptor 拦截器](https://github.com/houbb/rpc/tree/release_0.1.4)\n\n# 文档说明\n\n[0.0.1-server 服务端启动](https://github.com/houbb/rpc/blob/master/doc/dev/0.0.1-server%20服务端启动.md)\n\n[0.0.2-client 客户端启动](https://github.com/houbb/rpc/blob/master/doc/dev/0.0.2-client%20客户端启动.md)\n\n[0.0.3-客户端调用服务端](https://github.com/houbb/rpc/blob/master/doc/dev/0.0.3-客户端调用服务端.md)\n\n[0.0.4-p2p 客户端主动调用服务端](https://github.com/houbb/rpc/blob/master/doc/dev/0.0.4-p2p客户端主动调用服务端.md)\n\n[0.0.5-serial 序列化](https://github.com/houbb/rpc/blob/master/doc/dev/0.0.5-serial序列化.md)\n\n[0.0.6-通用反射调用](https://github.com/houbb/rpc/blob/master/doc/dev/0.0.6-通用反射调用.md)\n\n[0.0.7-timeout 超时处理](https://github.com/houbb/rpc/blob/master/doc/dev/0.0.7-timeout超时处理.md)\n\n[0.0.8-register 注册中心](https://github.com/houbb/rpc/blob/master/doc/dev/0.0.8-register注册中心.md)\n\n[0.0.9-load balance 负载均衡](https://github.com/houbb/rpc/blob/master/doc/dev/0.0.9-load-balance-负载均衡.md)\n\n[0.1.0-callType 调用方式](https://github.com/houbb/rpc/blob/master/doc/dev/0.1.0-callType-调用方式.md)\n\n[0.1.1-fail 失败策略](https://github.com/houbb/rpc/blob/master/doc/dev/0.1.1-fail-失败策略.md)\n\n[0.1.2-generic 泛化调用](https://github.com/houbb/rpc/blob/master/doc/dev/0.1.2-generic-泛化调用.md)\n\n[0.1.3-gracefully 优雅关闭](https://github.com/houbb/rpc/blob/master/doc/dev/0.1.3-gracefully-优雅关闭.md)\n\n[0.1.4-rpcInterceptor 拦截器](https://github.com/houbb/rpc/blob/master/doc/dev/0.1.4-rpcInterceptor-拦截器.md)\n\n# 测试代码\n\n从 v0.0.6 及其之后，为了让代码保持纯净，将测试代码全部放在 rpc-example。\n\n每个测试代码和实现版本一一对应。\n\nps: 这部分测试代码可以关注公众号【老马啸西风】，后台回复【rpc】领取。\n\n![qrcode](qrcode.jpg)\n\n# 后期 ROAD-MAP\n\n- [x] all 模块\n\n- [x] check 客户端启动检测\n  \n- [x] register 是否注册到注册中心\n  \n- [x] delay 延迟暴露\n\n- [x] 关闭时通知 register center\n\n- [x] 优雅关闭添加超时设置\n  \n- [x] heartbeat 心跳检测机制\n\n- [x] 完善 load-balance 实现\n  \n- [x] 完善 filter 实现\n  \n- [x] 完善 rpcInterceptor 实现\n\n- [ ] 失败重试的拓展\n  \n尝试其他服务端\n\n指定重试策略（sisyphus）\n\n- [ ] route 路由规则\n\n可以和 echo 回声检测一起实现\n\n- [ ] echo 回声服务\n\n- [ ] spring 整合\n\n- [ ] springboot 整合\n\n- [ ] telnet 命令行治理\n  \n- [ ] rpc-admin 控台管理\n\n服务治理\n\n- [ ] async 异步执行\n  \n- [ ] ~~cache 结果缓存？~~\n\n- [ ] ~~validator 参数校验~~\n\n- [ ] ~~服务降级~~\n\n- [ ] ~~version 多版本管理~~\n\n\n# 中间件等工具开源矩阵\n\n[heaven: 收集开发中常用的工具类](https://github.com/houbb/heaven)\n\n[rpc: 基于 netty4 实现的远程调用工具](https://github.com/houbb/rpc)\n\n[mq: 简易版 mq 实现](https://github.com/houbb/mq)\n\n[ioc: 模拟简易版 spring ioc](https://github.com/houbb/ioc)\n\n[mybatis: 简易版 mybatis](https://github.com/houbb/mybatis)\n\n[cache: 渐进式 redis 缓存](https://github.com/houbb/cache)\n\n[jdbc-pool: 数据库连接池实现](https://github.com/houbb/jdbc-pool)\n\n[sandglass: 任务调度时间工具框架](https://github.com/houbb/sandglass)\n\n[sisyphus: 支持注解的重试框架](https://github.com/houbb/sisyphus)\n\n[resubmit: 防止重复提交框架，支持注解](https://github.com/houbb/resubmit)\n\n[auto-log: 日志自动输出](https://github.com/houbb/auto-log)\n\n[async: 多线程异步并行框架](https://github.com/houbb/async)\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhoubb%2Frpc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhoubb%2Frpc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhoubb%2Frpc/lists"}