Crates.io | may_rpc |
lib.rs | may_rpc |
version | 0.1.6 |
source | src |
created_at | 2024-02-28 06:00:44.731817 |
updated_at | 2024-07-10 09:16:13.051916 |
description | RPC framework for Rust based on coroutine. |
homepage | https://github.com/Xudong-Huang/may_rpc |
repository | https://github.com/Xudong-Huang/may_rpc |
max_upload_size | |
id | 1156124 |
size | 65,242 |
Rust coroutine based RPC framework
may_rpc is an RPC framework for rust based on coroutines that powered by may with a focus on ease of use. Inspired by tarpc.
Add to your Cargo.toml
dependencies:
may_rpc = "0.1"
#[may_rpc::service]
trait Hello {
fn hello(&self, name: String) -> String;
}
#[derive(may_rpc::Server)]
#[service(Hello)]
struct HelloServer;
impl Hello for HelloServer {
fn hello(&self, name: String) -> String {
format!("Hello, {}!", name)
}
}
fn main() {
use may_rpc::TcpServer;
let addr = "127.0.0.1:10000";
let server = HelloServer.start(addr).unwrap();
let stream = may::net::TcpStream::connect(addr).unwrap();
let client = HelloClient::new(stream).unwrap();
println!("{}", client.hello("Mom".to_string()).unwrap());
server.shutdown();
}
The service
attribute macro expands to a collection of items that form an rpc service. In the above example, the service
macro is derived for a Hello rcp spec trait. This will generate HelloClient
for ease of use. Then the HelloServer
type derive Server
and impl Hello
trait for a rpc server. The generated types make it easy and ergonomic to write servers without dealing with sockets or serialization directly. Simply implement the generated traits, and you're off to the races!
See the examples directory for more examples.
All generated may_rpc RPC methods return Result<T, may_rpc::Error>
. the Error reason could be an io error or timeout.
Default timeout is 10s while you can configure through the RpcClient instance.
Just run the throughput example under this project
Machine Specs:
Test config:
may::config().set_workers(6).set_io_workers(4);
result:
$ cargo run --example=throughput --release
......
Running `target\release\examples\throughput.exe`
206127.39 rpc/second
impl
s serde
's Serialize
and Deserialize
can be used in
rpc signatures.This project is licensed under either of the following, at your option: