Rust library for rpcx rpc/microservice framework.
protocol and client lib.
server lib. You can register services bu Rust and they can be invoked by other languages.
Add this to your Cargo.toml:
toml
[dependencies]
rpcx_protocol = "0.1.0"
rpcx_derive = "0.1.0"
rpcx_client = "0.1.0"
Roadmap only supports client development so you need start a server by go server implementation.
Write a client:
```rust use rpcx_client::Client;
use std::collections::hash_map::HashMap; use std::error::Error as StdError;
use rmp_serde as rmps; use serde::{Deserialize, Serialize};
use rpcxderive::*; use rpcxprotocol::{Error, ErrorKind, Result, RpcxParam, SerializeType};
struct ArithAddArgs { #[serde(rename = "A")] a: u64, #[serde(rename = "B")] b: u64, }
struct ArithAddReply { #[serde(rename = "C")] c: u64, }
pub fn main() { let mut c: Client = Client::new("127.0.0.1:8972"); c.start().maperr(|err| println!("{}", err)).unwrap(); c.opt.serializetype = SerializeType::MsgPack;
let mut a = 1;
loop {
let service_path = String::from("Arith");
let service_method = String::from("Mul");
let metadata = HashMap::new();
let args = ArithAddArgs { a: a, b: 10 };
a = a + 1;
let reply: Option<Result<ArithAddReply>> =
c.call(service_path, service_method, false, metadata, &args);
if reply.is_none() {
continue;
}
let result_reply = reply.unwrap();
match result_reply {
Ok(r) => println!("received: {:?}", r),
Err(err) => println!("received err:{}", err),
}
}
} ```
rpcx-rs is distributed under the terms of both the MIT license.
See LICENSE-APACHE and LICENSE-MIT, and COPYRIGHT for details.