get_metadata_for_topic/
get-metadata-for-topic.rs

1//! # Build the debug version
2//!
3//! ```bash
4//! # export KAFKA_TOPIC=TOPIC_NAME
5//! cargo build --example get-metadata-for-topic  && export RUST_BACKTRACE=1 && export RUST_LOG=info,kafka_threadpool=info && ./target/debug/examples/get-metadata-for-topic
6//! ```
7//!
8extern crate pretty_env_logger;
9#[macro_use]
10extern crate log;
11
12use kafka_threadpool::start_threadpool::start_threadpool;
13
14/// main
15///
16/// Get metadata for a single topic stored in the environment variable:
17/// ``KAFKA_TOPIC``. If there is no ``KAFKA_TOPIC`` set, the process will exit.
18///
19#[tokio::main]
20async fn main() {
21    pretty_env_logger::init_timed();
22    let label = "get-metadata-for-topic";
23    let kafka_publisher = start_threadpool(Some(label)).await;
24
25    let topic = std::env::var("KAFKA_TOPIC").unwrap_or_else(|_| "".to_string());
26    if topic.is_empty() {
27        error!("please set a topic with: export KAFKA_TOPIC=TOPIC_NAME")
28    } else {
29        info!(
30            "{label} \
31            config={} \
32            getting all metadata",
33            kafka_publisher.config
34        );
35
36        kafka_publisher.get_metadata(true, Some(&topic)).await;
37    }
38
39    info!("shutting down");
40    // send shutdown message to all worker threads in the pool
41    match kafka_publisher.shutdown().await {
42        Ok(msg) => trace!("{msg}"),
43        Err(err_msg) => {
44            error!("publisher shutdown failed with err='{err_msg}'")
45        }
46    }
47}