Skip to main content

topic

Attribute Macro topic 

Source
#[topic]
Expand description

Register a typed topic struct (#[photon::topic]). Marks a struct as a Photon topic, generating typed publish/subscribe APIs.

Registers a topic descriptor in Quark inventory. With PhotonBuilder::auto_registry, the host discovers it at boot. Prefer EventType { … }.publish_on(&photon) with an explicit Photon handle.

AttributePurpose
name = "…"Topic stream name (required)
keyed_by = "field"Partition key field on the struct
shards = NVirtual shard count for consumer groups

Full attribute reference: photon::config. Getting started: Mode 1.

§Usage

use futures::StreamExt;
use photon::{topic, Photon, SubscribeOpts};

#[topic(name = "user.notifications", keyed_by = "user_id")]
pub struct NotificationPushed {
    pub user_id: String,
}

NotificationPushed { user_id: "u1".into() }
    .publish_on(photon)
    .await?;

let mut stream = NotificationPushed::subscribe_on(
    photon,
    SubscribeOpts::default_ephemeral(),
)
.await?;
if let Some(Ok(envelope)) = stream.next().await {
    let _ = envelope.payload.user_id;
}