pubsub.rs 1.1 KB
Newer Older
Ryan Olson's avatar
Ryan Olson committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
// SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

//! Publisher trait for distributed messaging.
//!
//! This module provides the `Publisher` trait used by the event pipeline.
//! Concrete implementations (NATS, Stub) remain in `dynamo-kvbm`.

use anyhow::Result;
use bytes::Bytes;
use futures::future::BoxFuture;

/// Publisher trait for sending messages to subjects.
///
/// Publishers are responsible for sending messages to named subjects.
/// Messages are delivered to all subscribers matching the subject pattern.
pub trait Publisher: Send + Sync {
    /// Publish a message to a subject.
    ///
    /// This queues the message for delivery and returns immediately.
    /// Use [`flush`](Publisher::flush) to ensure delivery.
    fn publish(&self, subject: &str, payload: Bytes) -> Result<()>;

    /// Flush pending messages to ensure delivery.
    ///
    /// Returns when all previously published messages have been acknowledged
    /// by the messaging system.
    fn flush(&self) -> BoxFuture<'static, Result<()>>;
}