{"id":25569438,"url":"https://github.com/baidu/Jprotobuf-rpc-socket","last_synced_at":"2026-03-19T12:30:22.144Z","repository":{"id":23169755,"uuid":"26525663","full_name":"baidu/Jprotobuf-rpc-socket","owner":"baidu","description":"Protobuf RPC是一种基于TCP协议的二进制RPC通信协议的Java实现","archived":false,"fork":false,"pushed_at":"2024-02-20T09:25:56.000Z","size":3680,"stargazers_count":531,"open_issues_count":47,"forks_count":220,"subscribers_count":78,"default_branch":"master","last_synced_at":"2025-02-12T21:04:52.885Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Java","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/baidu.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}},"created_at":"2014-11-12T08:07:51.000Z","updated_at":"2024-12-30T17:10:00.000Z","dependencies_parsed_at":"2024-11-13T13:48:16.933Z","dependency_job_id":"707c7f7e-96ad-4451-83f8-92703f61eb31","html_url":"https://github.com/baidu/Jprotobuf-rpc-socket","commit_stats":null,"previous_names":["baidu-ecom/jprotobuf-rpc-socket"],"tags_count":93,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/baidu%2FJprotobuf-rpc-socket","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/baidu%2FJprotobuf-rpc-socket/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/baidu%2FJprotobuf-rpc-socket/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/baidu%2FJprotobuf-rpc-socket/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/baidu","download_url":"https://codeload.github.com/baidu/Jprotobuf-rpc-socket/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239742400,"owners_count":19689308,"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":[],"created_at":"2025-02-21T00:02:22.668Z","updated_at":"2026-03-19T12:30:19.353Z","avatar_url":"https://github.com/baidu.png","language":"Java","funding_links":[],"categories":["开发框架"],"sub_categories":[],"readme":"Jprotobuf-rpc-socket\n====================\n\n## Build status\n\n[![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.baidu/jprotobuf-rpc-core/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.baidu/jprotobuf-rpc-core)\n\n\nProtobuf RPC是一种基于TCP协议的二进制高性能RPC通信协议实现。它以Protobuf作为基本的数据交换格式，支持完全基于POJO的发布方式，极大的简化了开发复杂性。\u003cbr\u003e\nFeatures:\u003cbr\u003e\n- 完全支持POJO方式发布，使用非常简单\n- 内置连接池，具备更高的性能，低延迟 QPS: 5w+\n- 支持自动重连功能\n- Client支持Ha的负载均衡功能\n- 支持附件发送\n- 压缩功能，支持GZip与Snappy\n- 支持多包拆分与合并功能\n- 支持多级超时设定，灵活控制请求超时时间\n- 支持RPC服务元数据动态生成，简单易用\n- 集成内置HTTP管理功能(3.1.1版本+)\n\n关联项目：\n[https://github.com/jhunters/jprotobuf](https://github.com/jhunters/jprotobuf \"https://github.com/jhunters/jprotobuf\")\u003cbr\u003e\ngolang 协议实现: [https://github.com/baidu-golang/baidurpc](https://github.com/baidu-golang/baidurpc \"https://github.com/baidu-golang/baidurpc\")\n\n\n## 使用示例 ##\n\n环境要求：JDK 6+\n```xml\n\u003cdependency\u003e \n\t\u003cgroupId\u003ecom.baidu\u003c/groupId\u003e\n\t\u003cartifactId\u003ejprotobuf-rpc-core\u003c/artifactId\u003e\n\t\u003cversion\u003e4.2.1\u003c/version\u003e\n\u003c/dependency\u003e\n\n\u003c!-- 提供spring扩展 --\u003e\n\u003cdependency\u003e\n\t\u003cgroupId\u003ecom.baidu\u003c/groupId\u003e\n\t\u003cartifactId\u003ejprotobuf-rpc-core-spring\u003c/artifactId\u003e\n\t\u003cversion\u003e4.2.1\u003c/version\u003e\n\u003c/dependency\u003e\n\n\u003c!-- 提供spring boot扩展 --\u003e\n\u003cdependency\u003e\n\t\u003cgroupId\u003ecom.baidu\u003c/groupId\u003e\n\t\u003cartifactId\u003ejprotobuf-rpc-spring-starter\u003c/artifactId\u003e\n\t\u003cversion\u003e4.2.1\u003c/version\u003e\n\u003c/dependency\u003e\n\n\u003c!-- 基于redis实现服务注册，发现功能 --\u003e\n\u003cdependency\u003e\n\t\u003cgroupId\u003ecom.baidu\u003c/groupId\u003e\n\t\u003cartifactId\u003ejprotobuf-rpc-registry-redis\u003c/artifactId\u003e\n\t\u003cversion\u003e4.2.1\u003c/version\u003e\n\u003c/dependency\u003e\n\n```\n使用Jprotobuf pre compile插件进行预编译，提升启动速度\n```xml\n    \u003cplugin\u003e\n        \u003cgroupId\u003ecom.baidu\u003c/groupId\u003e\n        \u003cartifactId\u003ejprotobuf-precompile-plugin\u003c/artifactId\u003e\n        \u003cversion\u003e1.2.8\u003c/version\u003e\n        \u003cconfiguration\u003e\n            \u003cskipErrorNoDescriptorsFound\u003etrue\u003c/skipErrorNoDescriptorsFound\u003e\n            \u003cfilterClassPackage\u003ecom.baidu\u003c/filterClassPackage\u003e\n        \u003c/configuration\u003e\n        \u003cexecutions\u003e\n            \u003cexecution\u003e\n                \u003cphase\u003ecompile\u003c/phase\u003e\n                \u003cgoals\u003e\n                    \u003cgoal\u003eprecompile\u003c/goal\u003e\n                \u003c/goals\u003e\n            \u003c/execution\u003e\n        \u003c/executions\u003e\n    \u003c/plugin\u003e\n```\nfilterClassPackage 用来指定进行预编译时需要扫描的package,目前只支持配置一个package名称\u003cbr\u003e\nmaven执行命令如下:\u003cbr\u003e\n```property\nmvn jprotobuf:precompile\nor\nmvn package \n```\n[下载发行包](http://repo1.maven.org/maven2/com/baidu/jprotobuf-rpc-core/)\n#### Qucik Start ####\nJprotobuf-rpc-socket基于JProtobuf基础上开发，可帮助大家开发中省去编写Google Protobuf的IDL描述文件的过程。\n\n##### 客户端开发 #####\n1.EchoService功用实现\n\nEchoService 提供一个echo方法 ，参数对象EchoInfo只有一个message属性。\n下面是EchoInfo对象定义\n```java\npublic class EchoInfo {\n    \n    @Protobuf\n    public String message;\n}\n\n```\n注解方式的定义可以极大简化大家的工作量，上面等同于下面的IDEL配置\n```property\npackage pkg;  \n\noption java_package = \"com.baidu.bjf.remoting.protobuf.rpc\";\n\n//这里声明输出的java的类名  \noption java_outer_classname = \"EchoInfo\";  \n\nmessage InterClassName {  \n  required string message = 1;\n} \n\n\n```\n2.定义EchoService接口\n```java\npublic interface EchoService {\n\n    /**\n     * To define a RPC client method. \u003cbr\u003e\n     * serviceName is \"echoService\"\n     * methodName is use default method name \"echo\"\n     * onceTalkTimeout is 200 milliseconds\n     * \n     * @param info\n     * @return\n     */\n    @ProtobufRPC(serviceName = \"echoService\", onceTalkTimeout = 200)\n    EchoInfo echo(EchoInfo info);\n}\n\n```\nRPC的方法必须要指定@ProtobufRPC注解. serviceName与methodName要与服务端保持一致。\n这里未指定methodName，则使用方法的名称 \"echo\"\n\n\n3.创建RPC Client进行访问\n```java\nRpcClient rpcClient = new RpcClient();\n// 创建EchoService代理\nProtobufRpcProxy\u003cEchoService\u003e pbrpcProxy = new ProtobufRpcProxy\u003cEchoService\u003e(rpcClient, EchoService.class);\npbrpcProxy.setPort(1031);\n// 动态生成代理实例\nEchoService echoService = pbrpcProxy.proxy();\nEchoInfo request = new EchoInfo();\nrequest.message = \"hello\";\nEchoInfo response = echoService.echo(request);\nrpcClient.stop();\n```\n\n##### 服务端开发 #####\n1.开发服务实现类\n```java\npublic class EchoServiceImpl {\n\n    @ProtobufRPCService(serviceName = \"echoService\", methodName = \"echo\")\n    public EchoInfo doEcho(EchoInfo info) {\n        EchoInfo ret = new EchoInfo();\n        ret.setMessage(\"hello:\" + info.message);\n        \n        return ret;\n    }\n}\n```\n服务发布的RPC方法必须用@ProtobufPRCService注解进行标识\n\n2.发布RPC服务\n```java\n\tRpcServer rpcServer = new RpcServer();\n\t\n\tEchoServiceImpl echoServiceImpl = new EchoServiceImpl();\n\trpcServer.registerService(echoServiceImpl);\n\trpcServer.start(1031);\n```\n上面的代码实现把 EchoServiceImpl 的RPC服务发布出去\n\n[更多使用说明](https://github.com/Baidu-ecom/Jprotobuf-rpc-socket/wiki/User-Guide)\n\n## 性能测试 ##\n\n机器配置：\n- Linux 64G内存 6核 12线程 \n- Intel(R) Xeon(R) CPU           E5645  @ 2.40GHz\n\n性能测试结果如下(客户端与服务端部署在同一台机器中)：\n单线程：平均QPS: 9000+\n多线程：QPS: 最高 40000+\n```property\n---------------------Performance Result-------------------------\nsend byte size: 44;receive byte size: 50\n|         total count|       time took(ms)|           average(ms)|                 QPS|             threads|\n|              100000|               11807|                     0|                8469|                   1|\n---------------------Performance Result-------------------------\n---------------------Performance Result-------------------------\nsend byte size: 44;receive byte size: 50\n|         total count|       time took(ms)|           average(ms)|                 QPS|             threads|\n|              100000|               10407|                     0|                9608|                   1|\n---------------------Performance Result-------------------------\n---------------------Performance Result-------------------------\nsend byte size: 1139;receive byte size: 1139\n|         total count|       time took(ms)|           average(ms)|                 QPS|             threads|\n|              100000|               11513|                     0|                8685|                   1|\n---------------------Performance Result-------------------------\n---------------------Performance Result-------------------------\nsend byte size: 44;receive byte size: 50\n|         total count|       time took(ms)|           average(ms)|                 QPS|             threads|\n|              100000|                5904|                     0|               16937|                   2|\n---------------------Performance Result-------------------------\n---------------------Performance Result-------------------------\nsend byte size: 44;receive byte size: 50\n|         total count|       time took(ms)|           average(ms)|                 QPS|             threads|\n|              100000|                3754|                     0|               26638|                   4|\n---------------------Performance Result-------------------------\n---------------------Performance Result-------------------------\nsend byte size: 44;receive byte size: 50\n|         total count|       time took(ms)|           average(ms)|                 QPS|             threads|\n|              100000|                1736|                     0|               57603|                  20|\n---------------------Performance Result-------------------------\n---------------------Performance Result-------------------------\nsend byte size: 1139;receive byte size: 1139\n|         total count|       time took(ms)|           average(ms)|                 QPS|             threads|\n|              100000|                2381|                     0|               41999|                  20|\n---------------------Performance Result-------------------------\n---------------------Performance Result-------------------------\nsend byte size: 1139;receive byte size: 1139\n|         total count|       time took(ms)|           average(ms)|                 QPS|             threads|\n|              100000|                2012|                     0|               49701|                  40|\n---------------------Performance Result-------------------------\n```\n\n```property\nLicense\n\n/*\n * Copyright 2002-2007 the original author or authors.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *      http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n ```\n \n ### 沟通群号：QQ: 644867264 ###  进群口令 jprotobuf\n ","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbaidu%2FJprotobuf-rpc-socket","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbaidu%2FJprotobuf-rpc-socket","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbaidu%2FJprotobuf-rpc-socket/lists"}