2023-01-05 10:27:18 +00:00
|
|
|
use df_consul::*;
|
|
|
|
|
|
|
|
#[tokio::main]
|
|
|
|
async fn main() {
|
2023-02-02 14:17:23 +00:00
|
|
|
let config = ConsulConfig {
|
|
|
|
addr: "http://localhost:8500".into(),
|
|
|
|
ca_cert: None,
|
|
|
|
tls_skip_verify: false,
|
|
|
|
client_cert: None,
|
|
|
|
client_key: None,
|
|
|
|
};
|
2023-01-05 10:27:18 +00:00
|
|
|
|
2023-02-02 14:17:23 +00:00
|
|
|
let consul = Consul::new(config, "").unwrap();
|
2023-01-05 10:27:18 +00:00
|
|
|
|
2023-02-02 14:17:23 +00:00
|
|
|
println!("== LIST NODES ==");
|
|
|
|
let nodes = consul.catalog_node_list(None).await.unwrap();
|
|
|
|
println!("{:?}", nodes);
|
2023-01-05 10:27:18 +00:00
|
|
|
|
2023-02-02 14:17:23 +00:00
|
|
|
if let Some(node) = nodes.first() {
|
|
|
|
println!("== NODE {} ==", node.node);
|
|
|
|
println!("{:?}", consul.catalog_node(&node.node, None).await.unwrap());
|
|
|
|
}
|
2023-01-05 10:27:18 +00:00
|
|
|
|
2023-02-02 14:17:23 +00:00
|
|
|
println!("== LIST SERVICES ==");
|
|
|
|
let services = consul.catalog_service_list(None).await.unwrap();
|
|
|
|
println!("{:?}", services);
|
|
|
|
|
|
|
|
if let Some(service) = services.keys().next() {
|
|
|
|
println!("== SERVICE NODES {} ==", service);
|
|
|
|
println!(
|
|
|
|
"{:?}",
|
|
|
|
consul.catalog_service_nodes(service, None).await.unwrap()
|
|
|
|
);
|
|
|
|
|
|
|
|
println!("== SERVICE HEALTH {} ==", service);
|
|
|
|
println!(
|
|
|
|
"{:?}",
|
|
|
|
consul
|
|
|
|
.health_service_instances(service, None)
|
|
|
|
.await
|
|
|
|
.unwrap()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
println!("== WATCHING EVERYTHING ==");
|
|
|
|
let mut watch = consul.watch_all_service_health();
|
|
|
|
loop {
|
|
|
|
if watch.changed().await.is_err() {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
println!("\n{:?}", watch.borrow_and_update());
|
|
|
|
}
|
2023-01-05 10:27:18 +00:00
|
|
|
}
|