jetstream_extra/lib.rs
1// Copyright 2025 Synadia Communications Inc.
2// Licensed under the Apache License, Version 2.0 (the "License");
3// you may not use this file except in compliance with the License.
4// You may obtain a copy of the License at
5//
6// http://www.apache.org/licenses/LICENSE-2.0
7//
8// Unless required by applicable law or agreed to in writing, software
9// distributed under the License is distributed on an "AS IS" BASIS,
10// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11// See the License for the specific language governing permissions and
12// limitations under the License.
13
14//! JetStream extensions for async-nats.
15//!
16//! This crate provides additional functionality for NATS JetStream that extends
17//! the capabilities of the async-nats client.
18//!
19//! # Features
20//!
21//! ## Batch Publishing
22//!
23//! The [batch_publish] module provides atomic batch publishing capabilities:
24//!
25//! ```no_run
26//! # use jetstream_extra::batch_publish::BatchPublishExt;
27//! # async fn example(client: impl BatchPublishExt) -> Result<(), Box<dyn std::error::Error>> {
28//! // Publish multiple messages as an atomic batch
29//! let mut batch = client.batch_publish().build();
30//! batch.add("events.1", "data1".into()).await?;
31//! batch.add("events.2", "data2".into()).await?;
32//! let ack = batch.commit("events.3", "final".into()).await?;
33//! # Ok(())
34//! # }
35//! ```
36//!
37//! ## Batch Fetching
38//!
39//! The [batch_fetch] module provides efficient batch fetching of messages from streams
40//! using the DIRECT.GET API:
41//!
42//! ```no_run
43//! # use jetstream_extra::batch_fetch::BatchFetchExt;
44//! # use futures::StreamExt;
45//! # async fn example(context: async_nats::jetstream::Context) -> Result<(), Box<dyn std::error::Error>> {
46//! // Fetch 100 messages from a stream
47//! let mut messages = context
48//! .get_batch("my_stream", 100)
49//! .send()
50//! .await?;
51//!
52//! while let Some(msg) = messages.next().await {
53//! let msg = msg?;
54//! println!("Message: {:?}", msg);
55//! }
56//! # Ok(())
57//! # }
58//! ```
59//!
60//! See the [batch_publish] and [batch_fetch] modules for detailed documentation.
61
62pub mod batch_fetch;
63pub mod batch_publish;
64
65pub use async_nats::Subject;
66/// Re-exported type returned by Direct Get operation.
67pub use async_nats::jetstream::message::StreamMessage;