ppoppo-infra 0.1.0

Backend-agnostic infrastructure traits for caching, queuing, and messaging
Documentation
//! Backend-agnostic publisher trait (write side of pub/sub).

use async_trait::async_trait;

use crate::Result;

/// Publisher (write side) of pub/sub messaging.
///
/// For combined publish+subscribe, use [`PubSub`](crate::PubSub) which
/// binds Publisher and [`Subscriber`](crate::Subscriber) to the same backend.
///
/// See [`PublisherExt`](crate::PublisherExt) for typed convenience methods.
#[async_trait]
pub trait Publisher: Send + Sync {
    /// Publish a JSON value to a channel.
    async fn publish(
        &self,
        channel: &str,
        payload: &serde_json::Value,
    ) -> Result<()>;

    /// Publish a raw string payload to a channel.
    async fn publish_raw(&self, channel: &str, payload: &str) -> Result<()>;

    /// Publish to multiple channels atomically.
    async fn publish_multi(
        &self,
        channels: &[&str],
        payload: &serde_json::Value,
    ) -> Result<()>;
}