{"id":13569392,"url":"https://github.com/neoremind/navi-pbrpc","last_synced_at":"2025-03-16T16:32:10.211Z","repository":{"id":34606824,"uuid":"38555105","full_name":"neoremind/navi-pbrpc","owner":"neoremind","description":"A protobuf based high performance rpc framework leveraging full-duplexing and asynchronous io with netty","archived":false,"fork":false,"pushed_at":"2016-02-08T09:40:33.000Z","size":151,"stargazers_count":166,"open_issues_count":0,"forks_count":59,"subscribers_count":21,"default_branch":"master","last_synced_at":"2025-02-27T11:43:44.246Z","etag":null,"topics":["rpc"],"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/neoremind.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}},"created_at":"2015-07-05T03:14:09.000Z","updated_at":"2024-09-10T03:27:36.000Z","dependencies_parsed_at":"2022-07-15T17:30:36.218Z","dependency_job_id":null,"html_url":"https://github.com/neoremind/navi-pbrpc","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/neoremind%2Fnavi-pbrpc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/neoremind%2Fnavi-pbrpc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/neoremind%2Fnavi-pbrpc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/neoremind%2Fnavi-pbrpc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/neoremind","download_url":"https://codeload.github.com/neoremind/navi-pbrpc/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243822295,"owners_count":20353500,"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":["rpc"],"created_at":"2024-08-01T14:00:39.455Z","updated_at":"2025-03-16T16:32:09.921Z","avatar_url":"https://github.com/neoremind.png","language":"Java","funding_links":[],"categories":["Java","开发框架"],"sub_categories":["RPC框架"],"readme":"## Navi-pbrpc\r![](https://api.travis-ci.org/neoremind/navi-pbrpc.svg?branch=master)\r[![Coverage Status](https://coveralls.io/repos/neoremind/navi-pbrpc/badge.svg)](https://coveralls.io/r/neoremind/navi-pbrpc)\r![](https://maven-badges.herokuapp.com/maven-central/com.baidu.beidou/navi-pbrpc/badge.svg)\r\rNavi-pbrpc provides a rpc solution for using protocol buffer. This library enables client and server to communicate in a peer-to-peer and full duplexing way. \r\rThe server-side is built upon [netty](http://netty.io/) which supports asynchronous and non-blocking io functionality, while the client-side provides a wide variety of options to communicate with server, which includes short live connection, keep-alive tcp connection, high availability and failover strategy.\r\r\r## Quick Start\r\r### 1. Prerequisite\r\rAdd the below dependency to pom.xml for a maven enabled project.\r\r\t\u003cdependency\u003e\r    \t\u003cgroupId\u003ecom.baidu.beidou\u003c/groupId\u003e\r    \t\u003cartifactId\u003enavi-pbrpc\u003c/artifactId\u003e\r    \t\u003cversion\u003e1.1.1\u003c/version\u003e\r\t\u003c/dependency\u003e\r\r\r### 2. Make a protobuf generated message\r\rUse `protoc` command to compile an **IDL proto file** and generate a java source file. \r\rThe IDL proto file can define the request and response type. Below is a simple sample:\r\r\r```\rpackage com.baidu.beidou.navi.pbrpc.demo.proto;\r \roption cc_generic_services = true;\r\rmessage DemoRequest {\r    optional int32 user_id = 1;\r}\r\rmessage DemoResponse {\r    optional int32 user_id = 1;\r    optional string user_name = 2;\r    enum GenderType {\r        MALE = 1;\r        FEMALE = 2;\r    }  \r    optional GenderType gender_type = 3;\r}\r```\r\r### 3. Develop server-side service\r\rDevelop a server-side service implementation. Below is an example based on the IDL generated java code from the previous step. Note that the method `doSmth` use the generated class `DemoRequest` as the parameter and `DemoResponse` as the return type. The logic here is pretty simple.\r\r    public class DemoServiceImpl implements DemoService {\r\r        @Override\r        public DemoResponse doSmth(DemoRequest req) {\r            DemoResponse.Builder builder = DemoResponse.newBuilder();\r            builder.setUserId(1);\r            builder.setUserName(\"name-1\");\r            builder.setGenderType(DemoResponse.GenderType.MALE);\r            return builder.build();\r        }\r    \r    }\r\r\r### 4. Expose service and start server\r\rRegister the service implementation and set the **service id** as 100. The id here will be used by the client later as a way of locating one specific service.\rThen start the server on port 8088.\r\r```\rPbrpcServer server = new PbrpcServer(8088);\rserver.register(100, new DemoServiceImpl());\rserver.start();\r```\r\r### 5. Develop client to invoke remote service\r\rThe framework provides many options to communicate with the server in terms of short live connection or keep-alive connection, high availablity and failover strategy. You can check out more on the [Tutorials wiki](https://github.com/neoremind/navi-pbrpc/wiki/Tutorials).\r\rBelow demostrates how to build a keep-alive, full-duplexing connection pool and make a rpc call.\r\r```\r// 1) Build client with keep-alive, full-duplexing pooled connection, and client read timeout is 60s\rPbrpcClient client = PbrpcClientFactory.buildPooledConnection(new PooledConfiguration(),\r        \"127.0.0.1\", 8088, 60000);\r\r// 2) Construct request data by using protobuf\rDemoRequest.Builder req = DemoRequest.newBuilder();\rreq.setUserId(1);\rbyte[] data = req.build().toByteArray();\r\r// 3) Build message by specifying the service id, and the property provider is used as a client trace sign to tell server who I am.\rPbrpcMsg msg = new PbrpcMsg();\rmsg.setServiceId(100);\rmsg.setProvider(\"beidou\");\rmsg.setData(data);\r\r// 4) Asynchronous invocation and return a future for client to hold\rCallFuture\u003cDemoResponse\u003e future = client.asyncTransport(DemoResponse.class, msg);\r\r// 5) Wait response to come. Once rpc call is done, the code will stop blocking right away.\rDemoResponse res = future.get();\r\r// 6) Print out result.\rSystem.out.println(res);\r```\r\r===\r\r### Dependencies\rNavi-pbrpc tries to leverage minimum amount of dependency libraries, so that project built upon Navi-pbrpc will not be overwhelmed by other unwanted libraries. The following are the dependencies.\r\r\r    [INFO] +- commons-pool:commons-pool:jar:1.5.7:compile\r    [INFO] +- com.google.protobuf:protobuf-java:jar:2.5.0:compile\r    [INFO] +- io.netty:netty-all:jar:4.0.28.Final:compile\r    [INFO] +- org.javassist:javassist:jar:3.18.1-GA:compile\r    [INFO] +- org.slf4j:slf4j-api:jar:1.7.7:compile\r    [INFO] +- org.slf4j:slf4j-log4j12:jar:1.7.7:compile\r    [INFO] |  \\- log4j:log4j:jar:1.2.17:compile\r\r===\r### More information\r\rClick here to [Tutorials wiki](https://github.com/neoremind/navi-pbrpc/wiki/Tutorials).\r\r### Supports \r\r![](http://neoremind.net/imgs/gmail.png)\r\r\r\r\r","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fneoremind%2Fnavi-pbrpc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fneoremind%2Fnavi-pbrpc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fneoremind%2Fnavi-pbrpc/lists"}