20个版本 (8个重大更新)
0.9.1 | 2022年8月12日 |
---|---|
0.8.1 | 2022年8月5日 |
0.8.0 | 2022年4月21日 |
0.7.0 | 2022年3月3日 |
0.5.2 | 2021年11月28日 |
#381 在 并发
每月46 次下载
11KB
221 代码行
norpc = 非远程过程调用
示例
#[norpc::service]
trait HelloWorld {
fn hello(s: String) -> String;
}
struct HelloWorldApp;
#[async_trait::async_trait]
impl HelloWorld for HelloWorldApp {
async fn hello(&self, s: String) -> String {
format!("Hello, {}", s)
}
}
let rep = tokio_test::block_on(async {
use norpc::runtime::*;
let app = HelloWorldApp;
let svc = HelloWorldService::new(app);
let (chan, server) = ServerBuilder::new(svc).build();
tokio::spawn(server.serve(TokioExecutor));
let mut cli = HelloWorldClient::new(chan);
cli.hello("World".to_owned()).await
});
assert_eq!(rep, "Hello, World");
用法
norpc = { version = "0.9", features = ["runtime", "tokio-executor"] }
- runtime: 使用norpc运行时
- tokio-executor: 使用tokio作为异步运行时。
- async-std-executor: 使用async-std作为异步运行时。
特性
- 通过异步通道支持进程内微服务。
- 异步运行时不依赖。
- 支持非
Send
类型。 - 支持客户端请求取消。
性能
norpc 比google/tarpc快约2倍。
为了比较纯开销,基准程序启动一个空操作服务器并从客户端发送请求。
noop request/1 time: [8.9181 us 8.9571 us 9.0167 us]
noop request (tarpc)/1 time: [15.476 us 15.514 us 15.554 us]
作者
Akira Hayakawa (@akiradeveloper)
依赖项
~1–12MB
~145K SLoC