summaryrefslogtreecommitdiff
path: root/examples/test.rs
diff options
context:
space:
mode:
Diffstat (limited to 'examples/test.rs')
-rw-r--r--examples/test.rs59
1 files changed, 44 insertions, 15 deletions
diff --git a/examples/test.rs b/examples/test.rs
index e7c34c8..ba29583 100644
--- a/examples/test.rs
+++ b/examples/test.rs
@@ -2,23 +2,52 @@ use df_consul::*;
#[tokio::main]
async fn main() {
- let config = ConsulConfig {
- addr: "http://localhost:8500".into(),
- ca_cert: None,
- tls_skip_verify: false,
- client_cert: None,
- client_key: None,
- };
+ let config = ConsulConfig {
+ addr: "http://localhost:8500".into(),
+ ca_cert: None,
+ tls_skip_verify: false,
+ client_cert: None,
+ client_key: None,
+ };
- let consul = Consul::new(config, "").unwrap();
+ let consul = Consul::new(config, "").unwrap();
- println!("== LIST NODES ==");
- let list_nodes = consul.list_nodes().await.unwrap();
- println!("{:?}", list_nodes);
+ println!("== LIST NODES ==");
+ let nodes = consul.catalog_node_list(None).await.unwrap();
+ println!("{:?}", nodes);
- println!("== CATALOG 1 ==");
- println!("{:?}", consul.watch_node("caribou", None).await.unwrap());
+ if let Some(node) = nodes.first() {
+ println!("== NODE {} ==", node.node);
+ println!("{:?}", consul.catalog_node(&node.node, None).await.unwrap());
+ }
- println!("== CATALOG 2 ==");
- println!("{:?}", consul.watch_node("cariacou", None).await.unwrap());
+ 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());
+ }
}