1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
//! Handler descriptor for `#[photon::subscribe]` inventory registration.
use std::future::Future;
use std::pin::Pin;
use photon_core::IdentityFactory;
use crate::error::Result;
use crate::models::Event;
/// Invokes a registered handler with reconstructed identity and the transport event.
///
/// The generated invoker reads `actor_json` / `payload_json` (and metadata) from `event`.
pub type HandlerInvoker = for<'a> fn(
&'a dyn IdentityFactory,
&'a Event,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'a>>;
/// Descriptor for a `#[photon::subscribe]` handler (inventory + executor dispatch).
#[derive(Clone, Copy)]
pub struct HandlerDescriptor {
/// Topic this handler listens on.
pub topic_name: &'static str,
/// Durable subscription name for broadcast handlers (empty for group handlers).
pub subscription_name: &'static str,
/// Stable registry key (`{topic}:{subscription}` or `{topic}:group:{group}`).
pub registry_key: &'static str,
/// Async dispatch entry point generated by the proc macro.
pub invoke: HandlerInvoker,
/// Consumer group id when load-balanced (mutually exclusive with durable name).
pub consumer_group: Option<&'static str>,
/// Override virtual shard count for group handlers.
pub group_shard_count: Option<u32>,
}
impl HandlerDescriptor {
/// Create a broadcast handler descriptor for inventory submission.
pub const fn new(
topic_name: &'static str,
subscription_name: &'static str,
registry_key: &'static str,
invoke: HandlerInvoker,
) -> Self {
Self {
topic_name,
subscription_name,
registry_key,
invoke,
consumer_group: None,
group_shard_count: None,
}
}
/// Create a consumer-group handler descriptor.
pub const fn new_group(
topic_name: &'static str,
consumer_group: &'static str,
group_shard_count: Option<u32>,
registry_key: &'static str,
invoke: HandlerInvoker,
) -> Self {
Self {
topic_name,
subscription_name: "",
registry_key,
invoke,
consumer_group: Some(consumer_group),
group_shard_count,
}
}
/// Whether this handler uses consumer-group delivery.
#[must_use]
pub const fn is_consumer_group(&self) -> bool {
self.consumer_group.is_some()
}
}
crate::inventory::collect!(HandlerDescriptor);
impl quark::Registrable for HandlerDescriptor {
fn registry_key(&self) -> &str {
self.registry_key
}
}