subscribe_tcp/
subscribe_tcp.rs

1use tokio::select;
2
3#[tokio::main]
4async fn main() -> Result<(), anyhow::Error> {
5    let client_type = simple_pub_sub::client::PubSubTcpClient {
6        server: "localhost".to_string(),
7        port: 6480,
8        cert: None,
9        cert_password: None,
10    };
11
12    // initialize the client.
13    let mut client =
14        simple_pub_sub::client::Client::new(simple_pub_sub::client::PubSubClient::Tcp(client_type));
15
16    client.connect().await?;
17    // subscribe to the given topic.
18    client.subscribe("abc".to_string()).await?;
19
20    loop {
21        select! {
22            msg = client.read_message()=>{
23                match  msg{
24                    Ok(msg)=>{
25                        println!("{}:{:?}", msg.topic, msg.message);
26                    }
27                    Err(e)=>{
28                        println!("Error: {:?}", e);
29                    }
30                }
31            }
32        }
33    }
34}