Skip to main content

kvbm_logical/
pubsub.rs

1// SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2// SPDX-License-Identifier: Apache-2.0
3
4//! Publisher trait for distributed messaging.
5//!
6//! This module provides the `Publisher` trait used by the event pipeline.
7//! Concrete implementations (NATS, Stub) remain in `dynamo-kvbm`.
8
9use anyhow::Result;
10use bytes::Bytes;
11use futures::future::BoxFuture;
12
13/// Publisher trait for sending messages to subjects.
14///
15/// Publishers are responsible for sending messages to named subjects.
16/// Messages are delivered to all subscribers matching the subject pattern.
17pub trait Publisher: Send + Sync {
18    /// Publish a message to a subject.
19    ///
20    /// This queues the message for delivery and returns immediately.
21    /// Use [`flush`](Publisher::flush) to ensure delivery.
22    fn publish(&self, subject: &str, payload: Bytes) -> Result<()>;
23
24    /// Flush pending messages to ensure delivery.
25    ///
26    /// Returns when all previously published messages have been acknowledged
27    /// by the messaging system.
28    fn flush(&self) -> BoxFuture<'static, Result<()>>;
29}