Skip to main content

PhotonBackend

Trait PhotonBackend 

Source
pub trait PhotonBackend: Send + Sync {
    // Required methods
    fn publish<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        topic_name: &'life1 str,
        topic_key: Option<&'life2 str>,
        actor_json: Value,
        payload_json: Value,
    ) -> Pin<Box<dyn Future<Output = Result<String, PhotonError>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait,
             Self: 'async_trait;
    fn subscribe(
        &self,
        topic_name: String,
        topic_key_filter: Option<String>,
        after_seq: Option<i64>,
    ) -> Pin<Box<dyn Stream<Item = Result<Event, PhotonError>> + Send>>;
    fn get_event<'life0, 'life1, 'async_trait>(
        &'life0 self,
        event_id: &'life1 str,
    ) -> Pin<Box<dyn Future<Output = Result<Option<Event>, PhotonError>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             'life1: 'async_trait,
             Self: 'async_trait;
    fn registry(&self) -> &TopicRegistry;
    fn get_checkpoint_seq<'life0, 'life1, 'life2, 'life3, 'async_trait>(
        &'life0 self,
        subscription_name: &'life1 str,
        topic_name: &'life2 str,
        topic_key: Option<&'life3 str>,
    ) -> Pin<Box<dyn Future<Output = Result<Option<i64>, PhotonError>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait,
             'life3: 'async_trait,
             Self: 'async_trait;
    fn set_checkpoint<'life0, 'life1, 'life2, 'life3, 'async_trait>(
        &'life0 self,
        subscription_name: &'life1 str,
        topic_name: &'life2 str,
        topic_key: Option<&'life3 str>,
        last_seq: i64,
    ) -> Pin<Box<dyn Future<Output = Result<(), PhotonError>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait,
             'life3: 'async_trait,
             Self: 'async_trait;

    // Provided methods
    fn telemetry_label(&self) -> &'static str { ... }
    fn capabilities(&self) -> StorageCapabilities { ... }
    fn list_by_topic<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        _topic_name: &'life1 str,
        _topic_key: Option<&'life2 str>,
        _after_seq: Option<i64>,
        _limit: usize,
    ) -> Pin<Box<dyn Future<Output = Result<Vec<Event>, PhotonError>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait,
             Self: 'async_trait { ... }
    fn list_recent<'life0, 'async_trait>(
        &'life0 self,
        _limit: usize,
    ) -> Pin<Box<dyn Future<Output = Result<Vec<Event>, PhotonError>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             Self: 'async_trait { ... }
}
Expand description

Backend for publish/subscribe delivery and checkpoint persistence.

Most hosts never implement this — use a storage adapter and the default GenericPhotonBackend. Custom delivery example:

use std::sync::Arc;
use photon_backend::{BackendContext, PhotonBackend};
use photon_runtime::Photon;

let _photon = Photon::builder()
    .backend_with_context(|ctx: BackendContext| {
        // return Ok(Arc::new(MyBackend::new(ctx)) as Arc<dyn PhotonBackend>)
        photon_backend::EmbeddedBackend::install_mem(ctx)
    })
    .auto_registry()
    .build()?;

Required Methods§

Source

fn publish<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, topic_name: &'life1 str, topic_key: Option<&'life2 str>, actor_json: Value, payload_json: Value, ) -> Pin<Box<dyn Future<Output = Result<String, PhotonError>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, Self: 'async_trait,

Append an event and return its event id.

§Contract
  • Returns the stable event_id assigned by the underlying storage port.
  • Ordering and dedupe are per (topic_name, topic_key) partition, not global.
Source

fn subscribe( &self, topic_name: String, topic_key_filter: Option<String>, after_seq: Option<i64>, ) -> Pin<Box<dyn Stream<Item = Result<Event, PhotonError>> + Send>>

Stream events for a topic partition, optionally replaying after after_seq.

§Contract
Source

fn get_event<'life0, 'life1, 'async_trait>( &'life0 self, event_id: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<Option<Event>, PhotonError>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, Self: 'async_trait,

Load a single event by id.

§Contract
Source

fn registry(&self) -> &TopicRegistry

Inventory-discovered topic descriptors.

Source

fn get_checkpoint_seq<'life0, 'life1, 'life2, 'life3, 'async_trait>( &'life0 self, subscription_name: &'life1 str, topic_name: &'life2 str, topic_key: Option<&'life3 str>, ) -> Pin<Box<dyn Future<Output = Result<Option<i64>, PhotonError>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait, Self: 'async_trait,

Load the last committed checkpoint seq for a subscription partition.

§Contract
  • Returns None when no checkpoint exists.
Source

fn set_checkpoint<'life0, 'life1, 'life2, 'life3, 'async_trait>( &'life0 self, subscription_name: &'life1 str, topic_name: &'life2 str, topic_key: Option<&'life3 str>, last_seq: i64, ) -> Pin<Box<dyn Future<Output = Result<(), PhotonError>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait, Self: 'async_trait,

Persist the high-water checkpoint seq for a subscription partition.

§Contract
  • last_seq must not regress; coalesced writes may batch behind the scenes.

Provided Methods§

Source

fn telemetry_label(&self) -> &'static str

Stable telemetry label for ops metrics (e.g. "mem", "nats").

Source

fn capabilities(&self) -> StorageCapabilities

Adapter capabilities (replay window, get-by-id support, …).

Source

fn list_by_topic<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, _topic_name: &'life1 str, _topic_key: Option<&'life2 str>, _after_seq: Option<i64>, _limit: usize, ) -> Pin<Box<dyn Future<Output = Result<Vec<Event>, PhotonError>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, Self: 'async_trait,

Bounded page of events for one topic (ops browse).

Default returns empty when the adapter does not support listing.

Source

fn list_recent<'life0, 'async_trait>( &'life0 self, _limit: usize, ) -> Pin<Box<dyn Future<Output = Result<Vec<Event>, PhotonError>> + Send + 'async_trait>>
where 'life0: 'async_trait, Self: 'async_trait,

Bounded cross-topic page of newest events (ops browse).

Default returns empty when the adapter does not support listing.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§