Crates.io | luoshu_rust_client |
lib.rs | luoshu_rust_client |
version | 0.1.0 |
source | src |
created_at | 2022-12-15 14:48:25.272864 |
updated_at | 2022-12-15 14:48:25.272864 |
description | Client for Luoshu |
homepage | |
repository | |
max_upload_size | |
id | 737957 |
size | 12,364 |
cargo install luoshu
不开放管理web接口
luoshu
开放管理web接口
luoshu --web
引入洛书客户端
[workspace.dependencies]
# ...
luoshu_rust_client = "0.1.0"
# ...
订阅配置信息,并注册服务到洛书并编写业务代码
use std::thread::sleep;
use luoshu_rust_client::LuoshuClient;
#[derive(Debug, Serialize, Deserialize, Clone)]
struct Config {
test1: String,
test2: Vec<usize>,
}
#[tokio::test]
async fn it_works() -> LuoshuClientResult<()> {
let mut client = LuoshuClient::new(15666, "test_rust_server".to_string(), None).await;
client
.subscribe_config(
"test_config2".to_string(),
|config: Config| println!("config changed:{:#?}", config),
None,
)
.await?;
tokio::spawn(async move {
client.registry().await.expect("TODO: panic message");
});
// 此处使用无限循环模拟服务的持续运行
loop {
println!("sleep");
sleep(Duration::from_secs(10))
}
}