#[subscribe]Expand description
Register an async handler (#[photon::subscribe]).
Marks a function as a subscription handler registered via inventory.
The host must call
Photon::start_executor
(Mode 1 hosts and Mode 2 workers) so inventory-registered handlers run. Publishers that
only emit events can omit the executor.
| Attribute | Purpose |
|---|---|
topic = "…" | Topic name to consume (required) |
durable = "name" | Checkpointed subscription name |
group = "id" | Consumer-group load balancing |
Full attribute reference: photon::config.
Getting started: Mode 2 worker.
§Usage (v1 — Box<dyn Actor>)
ⓘ
use photon::{topic, subscribe, Actor, Result};
#[topic(name = "user.notifications")]
pub struct NotificationPushed {
pub user_id: String,
}
#[subscribe(topic = "user.notifications", durable = "push-worker")]
async fn on_notification(
_actor: Box<dyn Actor>,
_event: NotificationPushed,
) -> Result<()> {
Ok(())
}§Actor bindings (v2)
The first parameter must be a simple identifier typed as one of:
Box<dyn Actor>— reconstruct as-is (v1)Arc<dyn Actor>—Arc::from(reconstruct()?)Box<Concrete>/Arc<Concrete>— downcast viaActor::into_any; failure maps toPhotonError::Identity
§Optional injectables (v2)
After (actor, payload) you may add trailing parameters detected by type path:
&Event— transport event (metadata + raw JSON)HandlerCtx— delivery metadata (event_id,topic_name,topic_key,seq)
Unknown trailing types are rejected at compile time.
The handler must be async and return photon::Result<()>. Runnable: subscribe_v2.