6个版本 (重大更新)
0.5.0 | 2024年5月6日 |
---|---|
0.4.0 | 2024年2月15日 |
0.3.1 | 2023年12月24日 |
0.2.0 | 2023年10月19日 |
0.1.0 | 2023年8月14日 |
#1604 in 网络编程
每月484次下载
225KB
4K SLoC
Selium
Selium是一个极具开发者友好性、可组合的消息平台,配置无需构建时间。
入门
Hello World
首先,创建一个新的Cargo项目
$ cargo new --bin hello-selium
$ cd hello-selium
$ cargo add futures
$ cargo add -F std selium
$ cargo add -F macros,rt tokio
将以下代码复制到hello-world/src/main.rs
use futures::{SinkExt, StreamExt};
use selium::{prelude::*, std::codecs::StringCodec};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let connection = selium::client()
.with_certificate_authority("certs/client/ca.der")? // your Selium cert authority
.with_cert_and_key(
"certs/client/localhost.der",
"certs/client/localhost.key.der",
)? // your client certificates
.connect("127.0.0.1:7001") // your Selium server's address
.await?;
let mut publisher = connection
.publisher("/some/topic") // choose a topic to group similar messages together
.with_encoder(StringCodec) // allows you to exchange string messages between clients
.open() // opens a new stream for sending data
.await?;
let mut subscriber = connection
.subscriber("/some/topic") // subscribe to the publisher's topic
.with_decoder(StringCodec) // use the same codec as the publisher
.open() // opens a new stream for receiving data
.await?;
// Send a message and close the publisher
publisher.send("Hello, world!".into()).await?;
publisher.finish().await?;
// Receive the message
if let Some(Ok(message)) = subscriber.next().await {
println!("Received message: {message}");
}
Ok(())
}
为了测试、开发Selium或直接开始操作,可以使用selium-tools
CLI生成一组自签名证书,用于与mTLS一起使用。
为此,安装selium-tools
二进制文件,然后运行gen-certs
命令。默认情况下,gen-certs
会将证书输出到certs/client/*
和certs/server/*
。您可以使用-s
和-c
参数分别覆盖这些路径。
$ cargo install selium-tools
$ cargo run --bin selium-tools gen-certs
接下来,打开一个新的终端窗口并启动一个新的Selium服务器,提供上一步生成的证书。
$ cargo install selium-tools
$ cargo install selium-server
$ cargo run --bin selium-server -- \
--bind-addr=127.0.0.1:7001 \
--ca certs/server/ca.der \
--cert certs/server/localhost.der \
--key certs/server/localhost.key.der
最后,在我们的原始终端窗口中运行客户端
$ cargo run
运行基准测试
在仓库中包含了一个benchmarks
二进制文件,其中包含发布/订阅客户端的全栈基准测试。
这些基准测试测量了客户端上编码/解码消息负载的性能,以及Selium服务器的响应能力。
要使用默认选项运行基准测试,执行以下命令
$ cd benchmarks
$ cargo run --release
这将使用默认值运行基准测试,这些默认值是针对基准配置参数提供的,应该会产生类似于以下内容的总结:
$ cargo run --release
Benchmark Results
---------------------
Number of Messages: 1,000,000
Number of Streams: 10
Message Size (Bytes): 32
| Duration | Total Transferred | Avg. Throughput | Avg. Latency |
| 1.3476 Secs | 30.52 MB | 22.65 MB/s | 1347.56 ns |
如果默认配置不足,请执行以下命令以查看基准参数列表。
$ cargo run -- --help
下一步
Selium是一个代理消息平台,这意味着它有一个客户端和服务器组件。查看client
和server
crates以获取更多详细信息。
我们还有用户指南,其中包含所有这些信息以及更多内容。我们的入门章节将引导您在5分钟或更短的时间内设置一个安全、可工作的Selium平台。
为Selium做出贡献
我们非常期待您的帮助!如果您想要某个功能,请首先提出问题以避免失望。虽然我们很高兴合并与我们的路线图相符的贡献,但您的功能可能并不完全符合。最好先进行检查。
依赖项
~20–33MB
~580K SLoC