subscribe_unix/
subscribe_unix.rs

1// define the on_message function (callback).
2pub fn on_msg(topic: String, message: Vec<u8>) {
3    println!("topic: {} message: {:?}", topic, message)
4}
5#[tokio::main]
6async fn main() -> Result<(), String> {
7    let client_type = simple_pub_sub::client::PubSubUnixClient {
8        path: "/tmp/simple.sock".to_string(),
9    };
10    // initialize the client.
11    let mut client = simple_pub_sub::client::Client::new(
12        simple_pub_sub::client::PubSubClient::Unix(client_type),
13    );
14    // set the callback function.
15    client.on_message(on_msg);
16    // connect the client.
17    let _ = client.connect().await;
18    // subscribe to the given topic.
19    let _ = client.subscribe("abc".to_string()).await;
20    Ok(())
21}