luoshu_rust_client

Crates.ioluoshu_rust_client
lib.rsluoshu_rust_client
version0.1.0
sourcesrc
created_at2022-12-15 14:48:25.272864
updated_at2022-12-15 14:48:25.272864
descriptionClient for Luoshu
homepage
repository
max_upload_size
id737957
size12,364
Hubert Shelley (hubertshelley)

documentation

README

洛书客户端

安装洛书

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))
    }
}
Commit count: 0

cargo fmt