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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
//! # Intercom
//!
//! A fully typed async wrapper for NATS with JetStream support.
//!
//! ## Features
//!
//! - Fully typed publish/subscribe with turbofish syntax support
//! - Pluggable codec support (MessagePack default, JSON optional)
//! - JetStream support with builder pattern
//! - Push and pull consumers
//! - Interest-based consumers
//! - Work queues
//! - Stream trait for subscribers
//! - Sink trait for publishers
//!
//! ## Codec Selection
//!
//! The library supports multiple serialization codecs via cargo features:
//! - `msgpack` (default) - MessagePack binary serialization
//! - `json` - JSON text serialization
//!
//! When creating a client, specify the codec type:
//!
//! ```no_run
//! use intercom::{Client, MsgPackCodec, Result};
//!
//! # async fn example() -> Result<()> {
//! // Using MessagePack (default)
//! let client = Client::<MsgPackCodec>::connect("nats://localhost:4222").await?;
//! # Ok(())
//! # }
//! ```
//!
//! Or with JSON:
//!
//! ```ignore
//! use intercom::{Client, JsonCodec, Result};
//!
//! # async fn example() -> Result<()> {
//! // Using JSON (requires `json` feature)
//! let client = Client::<JsonCodec>::connect("nats://localhost:4222").await?;
//! # Ok(())
//! # }
//! ```
//!
//! ## Example
//!
//! ```no_run
//! use intercom::{Client, MsgPackCodec, Result};
//! use serde::{Deserialize, Serialize};
//!
//! #[derive(Debug, Serialize, Deserialize)]
//! struct MyMessage {
//! content: String,
//! }
//!
//! #[tokio::main]
//! async fn main() -> Result<()> {
//! let client = Client::<MsgPackCodec>::connect("nats://localhost:4222").await?;
//!
//! // Type-safe publish
//! client.publish::<MyMessage>("subject", &MyMessage { content: "hello".into() }).await?;
//!
//! // Create a typed subscriber with Stream trait
//! let mut subscriber = client.subscribe::<MyMessage>("subject").await?;
//!
//! // Create a typed publisher with Sink trait
//! let publisher = client.publisher::<MyMessage>("subject");
//!
//! Ok(())
//! }
//! ```
//!
//! ## JetStream Example
//!
//! ```no_run
//! use intercom::{Client, MsgPackCodec, Result};
//! use intercom::jetstream::stream::RetentionPolicy;
//! use serde::{Deserialize, Serialize};
//! use futures::StreamExt;
//!
//! #[derive(Debug, Serialize, Deserialize)]
//! struct Event {
//! id: u64,
//! data: String,
//! }
//!
//! #[tokio::main]
//! async fn main() -> Result<()> {
//! let client = Client::<MsgPackCodec>::connect("nats://localhost:4222").await?;
//! let jetstream = client.jetstream();
//!
//! // Create a stream with builder pattern
//! let stream = jetstream
//! .stream_builder("events")
//! .subjects(vec!["events.>".to_string()])
//! .max_messages(1_000_000)
//! .create()
//! .await?;
//!
//! // Publish typed messages
//! jetstream.publish::<Event>("events.user", &Event {
//! id: 1,
//! data: "user created".to_string(),
//! }).await?;
//!
//! // Create a pull consumer with turbofish syntax
//! let consumer = stream
//! .pull_consumer_builder::<Event>("my-consumer")
//! .durable()
//! .create()
//! .await?;
//!
//! // Fetch messages with Stream trait
//! let mut messages = consumer.fetch(10).await?;
//! while let Some(result) = messages.next().await {
//! let msg = result?;
//! println!("Got: {:?}", msg.payload);
//! msg.ack().await?;
//! }
//!
//! Ok(())
//! }
//! ```
pub use Client;
pub use ;
pub use MsgPackCodec;
pub use JsonCodec;
pub use DefaultCodec;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use Publisher;
pub use ;