A plus consul client package for Rust, more functions for microservice.
set in Cargo dependencies
toml
[dependencies]
consul-rs-plus = "0.1.7"
```rust extern crate consulrsplus; use consulrsplus::Client;
fn main() { let mut c = Client::new("localhost", 8500); // debug enable c.debug = true;
let ok = c.kv_set("test-key", "test_value").unwrap();
assert_eq!(ok, true);
let kvpairs = c.kv_get("test-key").unwrap();
let kvpair = &kvpairs[0];
let v = kvpair.get_value().unwrap();
assert_eq!(b"test_value"[..].to_vec(), v);
let ok = c.kv_delete("test-key").unwrap();
assert_eq!(ok, true);
} ```
the test case write in function code file or tests folder, all nromal operation test in lib.rs. ```rust
mod tests { use crate::Client; use base64::Config; use crate::config;
#[test] fn testkvget() { let host = config::CONFIG["consuladdr"]; let client = Client::new(host, 8500); let mykeys = client.kvget("my-key").unwrap(); for k in mykeys { println!("k: {:?}", k); } }
} ```
if you write the micro service framework, the service register like rpcx-plus, folder tree style, for example, Echo service in folder(key, value) is
/mytest/Echo/tcp@8.8.8.8:999
, you can find the sample code for watch service change below,
they are in code repo. you can cache the service info when the service change(the folder tree change).
```rust
async fn testwatchfoldertreetmpsc() {
envlogger::init();
let folder = "mytest".tostring();
let mut nodesservice: Vec
``` you can run this test case in code repo.