Skip to main content

helios_subscriptions/channels/
mod.rs

1//! Channel dispatchers.
2//!
3//! Delivers notification bundles to subscriber endpoints via the configured
4//! channel type (rest-hook, WebSocket, email, FHIR messaging).
5
6pub mod email;
7pub mod messaging;
8pub mod rest_hook;
9pub mod websocket;
10pub mod ws_manager;
11pub mod ws_token;
12
13use async_trait::async_trait;
14
15use crate::error::SubscriptionError;
16use crate::manager::ActiveSubscription;
17
18/// The result of attempting to deliver a notification.
19#[derive(Debug)]
20pub enum DispatchResult {
21    /// The endpoint accepted the notification.
22    Success,
23    /// The delivery failed with a retryable error (e.g., 5xx, timeout).
24    RetryableError(String),
25    /// The delivery failed with a permanent error (e.g., 4xx).
26    PermanentError(String),
27}
28
29/// Trait for channel-specific notification delivery.
30#[async_trait]
31pub trait ChannelDispatcher: Send + Sync {
32    /// Deliver a notification bundle to the subscriber's endpoint.
33    async fn dispatch(
34        &self,
35        subscription: &ActiveSubscription,
36        notification_bundle: &serde_json::Value,
37    ) -> Result<DispatchResult, SubscriptionError>;
38
39    /// Perform the handshake sequence for a newly activated subscription.
40    async fn handshake(
41        &self,
42        subscription: &ActiveSubscription,
43        handshake_bundle: &serde_json::Value,
44    ) -> Result<DispatchResult, SubscriptionError>;
45}