summaryrefslogtreecommitdiff
path: root/examples/test.rs
blob: ba29583f2ffb76d62c9e97a0e619e2f49f71df4f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
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 consul = Consul::new(config, "").unwrap();

    println!("== LIST NODES ==");
    let nodes = consul.catalog_node_list(None).await.unwrap();
    println!("{:?}", nodes);

    if let Some(node) = nodes.first() {
        println!("== NODE {} ==", node.node);
        println!("{:?}", consul.catalog_node(&node.node, 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());
    }
}