{"id":13439922,"url":"https://github.com/smallnest/rpcx-rs","last_synced_at":"2025-04-05T21:09:02.067Z","repository":{"id":38421460,"uuid":"199313874","full_name":"smallnest/rpcx-rs","owner":"smallnest","description":"rpcx microservice framework in Rust","archived":false,"fork":false,"pushed_at":"2024-03-13T13:02:12.000Z","size":142,"stargazers_count":121,"open_issues_count":5,"forks_count":19,"subscribers_count":13,"default_branch":"master","last_synced_at":"2024-04-16T07:46:45.097Z","etag":null,"topics":["microservice","rpc","rpcx","rust"],"latest_commit_sha":null,"homepage":"https://rpcx.io","language":"Rust","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/smallnest.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":"2019-07-28T16:54:14.000Z","updated_at":"2024-04-29T10:00:52.133Z","dependencies_parsed_at":"2024-04-29T10:00:50.322Z","dependency_job_id":"24dfbe54-0621-4e31-b57f-cd88e0817566","html_url":"https://github.com/smallnest/rpcx-rs","commit_stats":{"total_commits":82,"total_committers":4,"mean_commits":20.5,"dds":0.04878048780487809,"last_synced_commit":"ac901ea8983252378f9ca30c93844409f2ae7f02"},"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smallnest%2Frpcx-rs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smallnest%2Frpcx-rs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smallnest%2Frpcx-rs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smallnest%2Frpcx-rs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/smallnest","download_url":"https://codeload.github.com/smallnest/rpcx-rs/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247399878,"owners_count":20932880,"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":["microservice","rpc","rpcx","rust"],"created_at":"2024-07-31T03:01:18.205Z","updated_at":"2025-04-05T21:09:02.040Z","avatar_url":"https://github.com/smallnest.png","language":"Rust","readme":"# rpcx-rs\n\n[![Build Status](https://travis-ci.org/smallnest/rpcx-rs.svg?branch=master)](https://travis-ci.org/smallnest/rpcx-rs)\n[![Crate](https://img.shields.io/crates/v/rpcx.svg)](https://crates.io/crates/rpcx)\n[![API](https://docs.rs/rpcx/badge.svg)](https://docs.rs/rpcx)\n\nRust library for [rpcx](https://rpcx.site) rpc/microservice framework.\n\nUse the **simplest** style to explore Rust function as cross-platform rpc services.\n\nIf you can write Rust functions, you can write rpc services. It is so easy.\n\n\nsee all exampes: [rpcx-rs-examples](https://github.com/smallnest/rpcx-rs/tree/master/examples).\n\n## Roadmap\n\n###  0.1.x\n\nprotocol and client/server lib.\n\n- [x] Protocol\n- [x] Client (call synchronous/asynchronous)\n- [x] support JSON, MessagePack and Protobuf\n- [x] Service implementation\n\n### 0.2.x\n\n- [ ] Service discovery\n  - [x] static multiple peers \n  - [x] etcd\n  - [ ] consul\n- [ ] service governance\n - [ ] Select Mode\n   - [x] RandomSelect,\n   - [x] RoundRobin\n   - [x] WeightedRoundRobin\n   - [ ] WeightedICMP\n   - [x] ConsistentHash\n   - [ ] Closest\n   - [ ] Custiomized\n - [ ] Faile Mode\n   - [x] Failover\n   - [x] Failfast\n   - [x] Failtry\n\n\n### 0.3.x\n\n- [ ] plugins\n- [ ] document\n- [ ] unit tests and integration tests\n- [ ] other features like implementation in Go\n\n## Usage\n\nAdd this to your Cargo.toml:\n\n```toml\n[dependencies]\nrpcx = \"0.2.0\"\n```\n\n## Example\n\n### Write the Argument and the Reply\n\nFirst you should write the argument and the reply. They are used by rpc services and clients.\n\n```rust\nuse std::error::Error as StdError;\n\nuse rmp_serde as rmps; \nuse serde::{Deserialize, Serialize};\n\nuse rpcx_derive::*;\nuse rpcx_protocol::{Error, ErrorKind, Result, RpcxParam, SerializeType};\n\n#[derive(RpcxParam, Default, Debug, Copy, Clone, Serialize, Deserialize)]\npub struct ArithAddArgs {\n    #[serde(rename = \"A\")]\n    pub a: u64,\n    #[serde(rename = \"B\")]\n    pub b: u64,\n}\n#[derive(RpcxParam, Default, Debug, Copy, Clone, Serialize, Deserialize)]\npub struct ArithAddReply {\n    #[serde(rename = \"C\")]\n    pub c: u64,\n}\n```\n\nYou must add `RpcxParam`、`Serialize`、`Deserialize` and `Default` traits in `derive`. Rpcx can add hepler methods for serialization.\n\nIf not, you need to implement `RpcxParam` and `Default` mannually.\n\nHere we defined `ArithAddArgs` as the argument type and `ArithAddReply` as the reply type.\n\n### Implement the server\n\n```rust\nuse mul_model::{ArithAddArgs, ArithAddReply};\nuse rpcx::*;\n\nfn add(args: ArithAddArgs) -\u003e ArithAddReply {\n    ArithAddReply { c: args.a + args.b }\n}\n\nfn mul(args: ArithAddArgs) -\u003e ArithAddReply {\n    ArithAddReply { c: args.a * args.b }\n}\n\nfn main() {\n    let mut rpc_server = Server::new(\"127.0.0.1:8972\".to_owned());\n    register_func!(\n        rpc_server,\n        \"Arith\",\n        \"Add\",\n        add,\n        ArithAddArgs,\n        ArithAddReply\n    );\n\n    register_func!(\n        rpc_server,\n        \"Arith\",\n        \"Mul\",\n        mul,\n        ArithAddArgs,\n        ArithAddReply\n    );\n\n    rpc_server.start().unwrap();\n}\n```\nHere we implement two services: `add` and `mul`. And we use `register_func!` macro to register them with their expored names(`service_path` and `service_method`). Clients can use the name to access them.\n\n### Implement client\n\nHere we use one client to access `Arith.Mul` service in a loop.\n\n```rust\nuse std::collections::hash_map::HashMap;\n\nuse mul_model::*;\nuse rpcx::Client;\nuse rpcx::{Result, SerializeType};\n\npub fn main() {\n    let mut c: Client = Client::new(\"127.0.0.1:8972\");\n    c.start().map_err(|err| println!(\"{}\", err)).unwrap();\n    c.opt.serialize_type = SerializeType::JSON;\n\n    let mut a = 1;\n    loop {\n        let service_path = String::from(\"Arith\");\n        let service_method = String::from(\"Mul\");\n        let metadata = HashMap::new();\n        let args = ArithAddArgs { a: a, b: 10 };\n        a += 1;\n\n        let reply: Option\u003cResult\u003cArithAddReply\u003e\u003e =\n            c.call(service_path, service_method, false, metadata, \u0026args);\n        match reply {\n            Some(Ok(r)) =\u003e println!(\"received: {:?}\", r),\n            Some(Err(err)) =\u003e println!(\"received err:{}\", err),\n            None =\u003e {}\n        }\n    }\n}\n```\n\nActually you can use this client to access rpcx services implemented by other program languages such as [service in go](https://github.com/rpcx-ecosystem/rpcx-examples3/tree/master/102basic).\n\n\nAs you see, only after three steps you have expored Rust functions (`add` and `mul`) as rpc services.\n\nYou can find more examples at [rpcx-rs/examples](https://github.com/smallnest/rpcx-rs/examples)\n\n## License\n\nrpcx-rs is distributed under the terms of both the MIT license.\n\nSee [LICENSE-APACHE](LICENSE-APACHE) and [LICENSE-MIT](LICENSE-MIT), and\n[COPYRIGHT](COPYRIGHT) for details.\n","funding_links":[],"categories":["Libraries","库 Libraries","库"],"sub_categories":["Network programming","网络编程 Network programming","网络编程"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsmallnest%2Frpcx-rs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsmallnest%2Frpcx-rs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsmallnest%2Frpcx-rs/lists"}