use rumqttd::{Broker, Config, Notification}; use std::thread; fn main() { let builder = tracing_subscriber::fmt() .pretty() .with_line_number(false) .with_file(false) .with_thread_ids(false) .with_thread_names(false); builder .try_init() .expect("initialized subscriber succesfully"); // As examples are compiled as seperate binary so this config is current path dependent. Run it // from root of this crate let config = config::Config::builder() .add_source(config::File::with_name("rumqttd.toml")) .build() .unwrap(); let config: Config = config.try_deserialize().unwrap(); dbg!(&config); let mut broker = Broker::new(config); let (mut link_tx, mut link_rx) = broker.link("singlenode").unwrap(); thread::spawn(move || { broker.start().unwrap(); }); link_tx.subscribe("#").unwrap(); let mut count = 0; loop { let notification = match link_rx.recv().unwrap() { Some(v) => v, None => continue, }; match notification { Notification::Forward(forward) => { count += 1; println!( "Topic = {:?}, Count = {}, Payload = {} bytes", forward.publish.topic, count, forward.publish.payload.len() ); } v => { println!("{v:?}"); } } } }