1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
// use simple-pub-sub

// define the on_message function (callback).
pub fn on_msg(topic: String, message: Vec<u8>) {
    println!("topic: {} message: {:?}", topic, message)
}
#[tokio::main]
async fn main() -> Result<(), String> {
    // initialize the client.
    let mut client = simple_pub_sub::client::Client::new("localhost".to_string(), 6480);
    // set the callback function.
    client.on_message(on_msg);
    // connect the client.
    let _ = client.connect().await;
    // subscribe to the given topic.
    let _ = client.subscribe("abc".to_string()).await;
    Ok(())
}