basic/
basic.rs

1use aurora_streams::{aurora::Observer, create_stream};
2
3const CHANNEL_NAME: &str = "my_channel";
4
5struct MySubscriber;
6
7impl Observer for MySubscriber {
8    fn on_message(&self, message: String) {
9        println!("Received message: {}", message);
10    }
11}
12
13#[tokio::main]
14async fn main() -> Result<(), Box<dyn std::error::Error>> {
15    let stream = create_stream().unwrap();
16
17    stream.create_channel(CHANNEL_NAME.to_string()).await?;
18
19    stream
20        .subscribe(CHANNEL_NAME.to_string(), MySubscriber)
21        .await?;
22
23    stream
24        .publish(CHANNEL_NAME.to_string(), "Hello, World!".to_string())
25        .await?;
26
27    tokio::time::sleep(tokio::time::Duration::from_secs(1)).await;
28    Ok(())
29}