{"id":34075483,"url":"https://github.com/kcangyan/broachrpc","last_synced_at":"2026-05-27T18:04:09.136Z","repository":{"id":63413117,"uuid":"567699537","full_name":"KcangYan/BroachRpc","owner":"KcangYan","description":"基于python的一个rpc框架，开箱即用。无注册中心模式的微服务框架","archived":false,"fork":false,"pushed_at":"2023-07-14T09:33:11.000Z","size":61,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2026-04-26T17:08:08.161Z","etag":null,"topics":["python","rpc","rpc-framework","udp"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/KcangYan.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2022-11-18T11:19:54.000Z","updated_at":"2024-07-04T06:44:45.000Z","dependencies_parsed_at":"2023-01-22T19:01:00.556Z","dependency_job_id":null,"html_url":"https://github.com/KcangYan/BroachRpc","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/KcangYan/BroachRpc","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KcangYan%2FBroachRpc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KcangYan%2FBroachRpc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KcangYan%2FBroachRpc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KcangYan%2FBroachRpc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/KcangYan","download_url":"https://codeload.github.com/KcangYan/BroachRpc/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KcangYan%2FBroachRpc/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33577663,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-05-27T02:00:06.184Z","response_time":53,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["python","rpc","rpc-framework","udp"],"created_at":"2025-12-14T09:46:44.113Z","updated_at":"2026-05-27T18:04:09.130Z","avatar_url":"https://github.com/KcangYan.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"###一个基于udp协议的RPC框架  BroachRpc\n\n**框架特点**\n~~~~text\n1. 无注册中心模式，采用”蔓延感染“的思路，将当前上线主机及其提供的服务注册到集群里\n的所有机器的路由表\n2. 所有通信基于udp实现\n3. 客户端自带负载均衡\n4. 开箱即用，使用python装饰器配置路由和调用即可，无需其他组件辅助。使用起来便捷简单。\n5. 下线主机会自动熔断，直接报错返回\n6. 负载模式扩展和自定义(开发中，目前只支持均衡负载)\n~~~~\n\n**配置参数**\n~~~python\n#参数路径导入框架主启动项，目前只支持json文件\nBroachFramework.run(\"./application1.json\")\n~~~~\n\n~~~~json\n{\n  \"name\": \"BroachRpc\",\n  \"version\": \"1.0.0\",\n  \"logLevel\": \"debug\",\n  \"params\": {\n    \"rpcPort\": 18080,\n    \"rpcIp\": \"127.0.0.1\",\n    \"clusterAddress\" : [\"127.0.0.1:18080\"],\n    \"rpcTimeOut\": 6,\n    \"udpTimeOut\": 3,\n    \"threadPool\" : {\n      \"core\" : 3,\n      \"threadMax\" : 15,\n      \"keepAliveTime\" : 9,\n      \"queueMax\" :  1000,\n      \"isExcInfo\" : \"False\",\n      \"createThreadThreshold\" : 2\n    }\n  }\n}\n~~~~\n~~~~text\n  参数解释：\n  name 实例主机或服务名\n  version 服务版本号\n  logLevel 框架日志打印级别\n  系统参数params\n    rpcPort 当前实例主机rpc服务接收端口\n    rpcIp 当前实例主机rpc服务接收地址\n    clusterAddress 配置蔓延地址，指向当前运行的RPC集群中的某一台或多台存活的主机即可\n    rpcTimeOut rpc调用超时时间\n    udpTimeOut 底层udp双向协议超时时间\n  框架内部线程池threadPool配置\n    core 核心线程数\n    threadMax 最大线程数\n    keepAliveTime 空闲线程存活时间 秒 \n    queueMax 线程池任务队列长度\n    isExcInfo 线程池任务队列溢出以后 true为报错 false为交由提交任务的线程执行溢出任务\n    createThreadThreshold 当队列任务数任务超过此项值时 创建新线程消费任务\n~~~~\n\n**启动与使用**\n\n~~~~python\nfrom BroachRpc import BroachFramework,BroachApply\n\n#启动框架，框架启动函数为异步函数 不会阻塞当前线程\nBroachFramework.run(\"./application1.json\")\n\n#服务提供端 默认使用函数名作为服务名\n@BroachApply.rpcRoute()\ndef work00():\n    return \"127.0.0.1:18080\"\n\n@BroachApply.rpcRoute(name=\"自定义服务名\")\ndef work01(x,y):\n    return x+y\n\n#服务调用者 默认使用函数名去调用\n@BroachApply.rpcCall()\ndef work00(*args, **kwargs):\n    pass\n@BroachApply.rpcCall(name=\"work01\")\ndef t1(*args, **kwargs):\n    pass\n@BroachApply.rpcCall(name=\"work02\")\ndef t2(*args, **kwargs):\n    pass\n\n#在需要的地方使用配置了rpcCall装饰器的函数即可调用集群中的函数\nwork00()\nt1(1,2)\nt2(2,3)\n~~~~\n\n**原理简述**\n\n~~~~text\n1. 底层通信使用udp作为消息协议是因为我认为在rpc调用的场景中应该都是服务器与服务器之间的通信\n甚至大部分集群都在同一个内网网段下，几乎不存在udp消息丢失的问题。\n2. 虽然几乎不存在udp消息丢失的情况但框架还是参考了QUIC协议设计了一个应答模式保证消息的送达与响应\n具体实现如下\n2.1 当rpc消息发起时，A服务器发送一个udp包到B服务器同时A服务器阻塞等待B服务器的udp包回答\n如果超时不回答则放弃此次通信直接结束。\n2.2 包消息中有请求id 和 响应id来区分发送和接收的是请求包还是响应包。当收到对应请求id的响应包时，\n框架会结束请求线程的阻塞并将响应结果返给请求线程\n2.3 同时诸如注册 心跳维护等等框架系统级别的信息交互则直接采用udp通信不做响应回调，毕竟服务器之间\n如果长时间udp包都无法得到回应的话，则认为对方掉线也没什么问题。\n3. 无注册中心模式，参考redis集群的扩展，新实例上线时 只需配置rpc集群中的某一台节点的地址和端口即可\n实现实例的接入和服务注册\n具体实现如下\n3.1 当前主机上线时 会向配置的地址请求当前所有的实例地址，收到回应后当前主机会向实例列表里所有\n的主机发送一个上线通知，收到上线通知的主机会将当前主机加入到本机的实例列表里。\n3.2 通知上线结束后当前主机会rpc调用内部函数将当前主机的服务注册到所有实例里，同时收到上线通知的主机也会将\n本机的服务注册到当前主机的rpc路由表里\n3.3 至此第一次上线完成。当第一次上线结束后，当前主机的实例列表里的主机如果没有全部响应，则会有定时任务朝这些\n没有响应的主机发送上线通知直至全部主机都完成上线通知工作。\n3.4 在定时任务中也会有心跳维护的能力，当实例列表中某些机器长时间没有心跳以后，则任务主机下线，在rpc调用时会\n直接抛出异常终止调用，防止掉线主机占用过多通信线程导致任务堆积溢出。\n~~~~\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkcangyan%2Fbroachrpc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkcangyan%2Fbroachrpc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkcangyan%2Fbroachrpc/lists"}