#![allow(missing_docs)]
#![allow(clippy::unused_async, clippy::used_underscore_binding)]
use std::sync::Arc;
use photon::{
subscribe, topic, JsonIdentityFactory, Photon, Actor,
};
#[topic(name = "examples.greeting", keyed_by = "name")]
pub struct GreetingSent {
pub name: String,
pub message: String,
}
#[subscribe(topic = "examples.greeting", durable = "logger")]
async fn on_greeting(_actor: Box<dyn Actor>, event: GreetingSent) -> photon::Result<()> {
tracing::info!(name = %event.name, message = %event.message, "received greeting");
Ok(())
}
#[tokio::main]
async fn main() -> anyhow::Result<()> {
tracing_subscriber::fmt()
.with_env_filter("info")
.init();
let photon = Photon::builder().auto_registry().build()?;
photon.start_executor(Arc::new(JsonIdentityFactory))?;
tokio::time::sleep(std::time::Duration::from_millis(50)).await;
let event_id = GreetingSent {
name: "world".into(),
message: "hello from embedded_mem example".into(),
}
.publish_on(&photon)
.await?;
tracing::info!(event_id = %event_id, "published");
tokio::time::sleep(std::time::Duration::from_millis(200)).await;
Ok(())
}