pub struct GenericMessagePersistenceManager<T: MessagesManagerTrait> {
messages_manager: Arc<T>,
persistence_task: Arc<AbortOnDrop<Result<()>>>,
}Expand description
High-level message persistence manager that automatically stores messages.
The MessagePersistenceManager bridges the gap between real-time messaging
and persistent storage by:
- Automatic Persistence: Stores all message events as they occur
- Relay Sync Tracking: Tracks which messages have been synced to which relays
- Non-blocking Operation: Runs persistence in the background without affecting message flow
This manager operates by subscribing to the message events stream from MessagesManager and automatically persisting all events to the configured storage backend.
Fields§
§messages_manager: Arc<T>The messages manager that this persistence manager wraps
persistence_task: Arc<AbortOnDrop<Result<()>>>Handle to the background persistence task
Implementations§
Source§impl<T: MessagesManagerTrait> GenericMessagePersistenceManager<T>
impl<T: MessagesManagerTrait> GenericMessagePersistenceManager<T>
Sourcepub fn messages_manager(&self) -> &Arc<T>
pub fn messages_manager(&self) -> &Arc<T>
Get a reference to the underlying MessagesManager
This provides explicit access to the MessagesManager for cases where method discovery is important or when you need to pass it to other components.
Sourcepub async fn load_subscription_state(
storage: &dyn MessageStorage,
relay_id: &KeyId,
) -> Result<Option<SubscriptionState>>
pub async fn load_subscription_state( storage: &dyn MessageStorage, relay_id: &KeyId, ) -> Result<Option<SubscriptionState>>
Load subscription state from storage for a specific relay
Sourcepub async fn load_all_subscription_states(
storage: &dyn MessageStorage,
) -> Result<HashMap<KeyId, SubscriptionState>>
pub async fn load_all_subscription_states( storage: &dyn MessageStorage, ) -> Result<HashMap<KeyId, SubscriptionState>>
Load all subscription states from storage
Sourceasync fn new(
storage: Arc<dyn MessageStorage>,
messages_manager: Arc<T>,
relay_id: KeyId,
) -> Result<Self>
async fn new( storage: Arc<dyn MessageStorage>, messages_manager: Arc<T>, relay_id: KeyId, ) -> Result<Self>
Create a new MessagePersistenceManager with the given components.
This starts the background persistence task immediately.
§Arguments
storage- The storage implementation to persist messages tomessages_manager- The messages manager to monitor for eventsrelay_pubkey- Optional relay public key for sync trackingbuffer_size- Optional buffer size for the task queue
Sourceasync fn handle_message_event(
storage: &dyn MessageStorage,
event: &MessageEvent,
relay_id: &KeyId,
) -> Result<()>
async fn handle_message_event( storage: &dyn MessageStorage, event: &MessageEvent, relay_id: &KeyId, ) -> Result<()>
Handle a single message event by persisting it
Sourcepub fn is_running(&self) -> bool
pub fn is_running(&self) -> bool
Check if the persistence task is still running
Source§impl GenericMessagePersistenceManager<MessagesManager>
impl GenericMessagePersistenceManager<MessagesManager>
Sourcepub fn builder() -> MessagePersistenceManagerBuilder
pub fn builder() -> MessagePersistenceManagerBuilder
Create a new MessagePersistenceManager builder
Sourcepub fn inner_messages_manager(&self) -> &MessagesManager
pub fn inner_messages_manager(&self) -> &MessagesManager
Get a reference to the inner MessagesManager for use with components that require the concrete type (like PqxdhProtocolHandler)
This method is only available on the concrete MessagePersistenceManager type alias, not the generic version.
Trait Implementations§
Source§impl<T: Clone + MessagesManagerTrait> Clone for GenericMessagePersistenceManager<T>
impl<T: Clone + MessagesManagerTrait> Clone for GenericMessagePersistenceManager<T>
Source§fn clone(&self) -> GenericMessagePersistenceManager<T>
fn clone(&self) -> GenericMessagePersistenceManager<T>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<T: Debug + MessagesManagerTrait> Debug for GenericMessagePersistenceManager<T>
impl<T: Debug + MessagesManagerTrait> Debug for GenericMessagePersistenceManager<T>
Source§impl<T: MessagesManagerTrait + 'static> MessagesManagerTrait for GenericMessagePersistenceManager<T>
impl<T: MessagesManagerTrait + 'static> MessagesManagerTrait for GenericMessagePersistenceManager<T>
Source§fn message_events_stream(&self) -> Receiver<MessageEvent>
fn message_events_stream(&self) -> Receiver<MessageEvent>
Source§fn get_subscription_state_updates<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Subscriber<SubscriptionState, AsyncLock>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn get_subscription_state_updates<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Subscriber<SubscriptionState, AsyncLock>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Source§fn subscribe<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn subscribe<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Source§fn publish<'life0, 'async_trait>(
&'life0 self,
message: MessageFull,
) -> Pin<Box<dyn Future<Output = Result<PublishResult>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn publish<'life0, 'async_trait>(
&'life0 self,
message: MessageFull,
) -> Pin<Box<dyn Future<Output = Result<PublishResult>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Source§fn ensure_contains_filter<'life0, 'async_trait>(
&'life0 self,
filter: Filter,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn ensure_contains_filter<'life0, 'async_trait>(
&'life0 self,
filter: Filter,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Source§fn messages_stream(&self) -> Receiver<StreamMessage>
fn messages_stream(&self) -> Receiver<StreamMessage>
Source§fn catch_up_stream(&self) -> Receiver<CatchUpResponse>
fn catch_up_stream(&self) -> Receiver<CatchUpResponse>
Source§fn filtered_messages_stream(
&self,
filter: Filter,
) -> Pin<Box<dyn Stream<Item = Box<MessageFull>> + Send>>
fn filtered_messages_stream( &self, filter: Filter, ) -> Pin<Box<dyn Stream<Item = Box<MessageFull>> + Send>>
Source§fn catch_up_and_subscribe<'life0, 'async_trait>(
&'life0 self,
filter: Filter,
since: Option<String>,
) -> Pin<Box<dyn Future<Output = Result<Pin<Box<dyn Stream<Item = Box<MessageFull>> + Send>>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn catch_up_and_subscribe<'life0, 'async_trait>(
&'life0 self,
filter: Filter,
since: Option<String>,
) -> Pin<Box<dyn Future<Output = Result<Pin<Box<dyn Stream<Item = Box<MessageFull>> + Send>>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Source§fn user_data<'life0, 'async_trait>(
&'life0 self,
author: KeyId,
storage_key: StoreKey,
) -> Pin<Box<dyn Future<Output = Result<Option<MessageFull>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn user_data<'life0, 'async_trait>(
&'life0 self,
author: KeyId,
storage_key: StoreKey,
) -> Pin<Box<dyn Future<Output = Result<Option<MessageFull>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Source§fn check_messages<'life0, 'async_trait>(
&'life0 self,
message_ids: Vec<MessageId>,
) -> Pin<Box<dyn Future<Output = Result<Vec<Option<String>>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn check_messages<'life0, 'async_trait>(
&'life0 self,
message_ids: Vec<MessageId>,
) -> Pin<Box<dyn Future<Output = Result<Vec<Option<String>>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Option<String> in the same order as the input, where: Read more