faucet_source_nats/lib.rs
1#![cfg_attr(docsrs, feature(doc_cfg))]
2
3//! # faucet-source-nats
4//!
5//! A [NATS](https://nats.io) source for `faucet-stream`. Subscribes to a
6//! subject (core NATS, with `*`/`>` wildcards and optional queue groups) or
7//! pulls from a durable JetStream consumer, drains until `max_messages` or
8//! `idle_timeout_secs` fires, and yields each message payload as a JSON record
9//! (valid JSON passes through; anything else becomes a JSON string).
10//!
11//! Core NATS is fire-and-forget (at-most-once: a message published while the
12//! source is not subscribed is never seen), so runs carry no bookmark and are
13//! not resumable. In JetStream mode each page's messages are acked after the
14//! page is written, giving at-least-once delivery.
15//!
16//! ```no_run
17//! use faucet_source_nats::{NatsSource, NatsSourceConfig};
18//! # async fn ex() -> Result<(), faucet_core::FaucetError> {
19//! let source = NatsSource::new(NatsSourceConfig::new("events.>")).await?;
20//! # let _ = source;
21//! # Ok(())
22//! # }
23//! ```
24
25pub mod config;
26pub mod stream;
27
28pub use config::{NatsOnDecodeError, NatsSourceConfig, NatsValueFormat};
29pub use stream::NatsSource;
30
31// Re-export shared config types so downstream users import from one place.
32pub use faucet_common_nats::{NatsAuth, NatsConnectionConfig, NatsTls};
33pub use faucet_core::{FaucetError, Source};
34
35/// The connector's static descriptor (RFC 0013): its capabilities, answered from config alone.
36pub const DESCRIPTOR: faucet_core::ConnectorDescriptor =
37 faucet_core::ConnectorDescriptor::new("nats", faucet_core::capabilities::plain_source);