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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// Copyright 2025 Synadia Communications Inc.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//! JetStream extensions for async-nats.
//!
//! This crate provides additional functionality for NATS JetStream that extends
//! the capabilities of the async-nats client.
//!
//! # Features
//!
//! ## Batch Publishing
//!
//! The [batch_publish] module provides atomic batch publishing capabilities:
//!
//! ```no_run
//! # use jetstream_extra::batch_publish::BatchPublishExt;
//! # async fn example(client: impl BatchPublishExt) -> Result<(), Box<dyn std::error::Error>> {
//! // Publish multiple messages as an atomic batch
//! let mut batch = client.batch_publish().build();
//! batch.add("events.1", "data1".into()).await?;
//! batch.add("events.2", "data2".into()).await?;
//! let ack = batch.commit("events.3", "final".into()).await?;
//! # Ok(())
//! # }
//! ```
//!
//! ## Fast Ingest Batch Publishing
//!
//! The [batch_publish_fast] module provides high-throughput, non-atomic batch publishing
//! using JetStream's fast-ingest feature (nats-server 2.14+):
//!
//! ```no_run
//! # use jetstream_extra::batch_publish_fast::FastPublishExt;
//! # async fn example(client: impl FastPublishExt) -> Result<(), Box<dyn std::error::Error>> {
//! let mut batch = client.fast_publish().build()?;
//! for i in 0..1000 {
//! batch.add("events.data", format!("msg {i}").into()).await?;
//! }
//! let ack = batch.commit("events.done", "final".into()).await?;
//! # Ok(())
//! # }
//! ```
//!
//! ## Batch Fetching
//!
//! The [batch_fetch] module provides efficient batch fetching of messages from streams
//! using the DIRECT.GET API:
//!
//! ```no_run
//! # use jetstream_extra::batch_fetch::BatchFetchExt;
//! # use futures::StreamExt;
//! # async fn example(context: async_nats::jetstream::Context) -> Result<(), Box<dyn std::error::Error>> {
//! // Fetch 100 messages from a stream
//! let mut messages = context
//! .get_batch("my_stream", 100)
//! .send()
//! .await?;
//!
//! while let Some(msg) = messages.next().await {
//! let msg = msg?;
//! println!("Message: {:?}", msg);
//! }
//! # Ok(())
//! # }
//! ```
//!
//! See the [batch_publish] and [batch_fetch] modules for detailed documentation.
pub use Subject;
/// Re-exported type returned by Direct Get operation.
pub use StreamMessage;