1
1
//! Rust client library for [HStreamDB](https://hstream.io/)
2
2
3
3
//! ## Write Data to Streams
4
+ //!
4
5
//! ```
5
6
//! use std::env;
6
7
//!
67
68
//! Ok(())
68
69
//! }
69
70
//! ```
71
+ //!
72
+ //! ## Read Data from Subscriptions
73
+ //!
74
+ //! ```
75
+ //! use std::env;
76
+ //!
77
+ //! use hstreamdb::client::Client;
78
+ //! use hstreamdb::{SpecialOffset, Subscription};
79
+ //! use tokio_stream::StreamExt;
80
+ //!
81
+ //! async fn consume_example() -> anyhow::Result<()> {
82
+ //! let addr = env::var("TEST_SERVER_ADDR").unwrap();
83
+ //! let mut client = Client::new(addr).await.unwrap();
84
+ //!
85
+ //! let stream_name = "test_stream";
86
+ //! let subscription_id = "test_subscription";
87
+ //!
88
+ //! client
89
+ //! .create_subscription(Subscription {
90
+ //! subscription_id: subscription_id.to_string(),
91
+ //! stream_name: stream_name.to_string(),
92
+ //! ack_timeout_seconds: 60 * 60,
93
+ //! max_unacked_records: 1000,
94
+ //! offset: SpecialOffset::Earliest,
95
+ //! })
96
+ //! .await?;
97
+ //! println!("{:?}", client.list_subscriptions().await?);
98
+ //!
99
+ //! let mut stream = client
100
+ //! .streaming_fetch("test_consumer".to_string(), subscription_id.to_string())
101
+ //! .await
102
+ //! .unwrap();
103
+ //! let mut records = Vec::new();
104
+ //! while let Some((record, ack)) = stream.next().await {
105
+ //! println!("{record:?}");
106
+ //! records.push(record);
107
+ //! ack().unwrap();
108
+ //! if records.len() == 10 * 100 {
109
+ //! println!("done");
110
+ //! break;
111
+ //! }
112
+ //! }
113
+ //!
114
+ //! client
115
+ //! .delete_subscription(subscription_id.to_string(), true)
116
+ //! .await?;
117
+ //!
118
+ //! Ok(())
119
+ //! }
120
+ //! ```
70
121
71
- #![ feature( try_blocks) ]
72
122
#![ feature( box_syntax) ]
73
123
#![ feature( default_free_fn) ]
74
124
@@ -80,4 +130,6 @@ pub mod consumer;
80
130
pub mod producer;
81
131
pub mod utils;
82
132
83
- pub use common:: { CompressionType , Error , Payload , Record , Result , Stream , Subscription } ;
133
+ pub use common:: {
134
+ CompressionType , Error , Payload , Record , Result , SpecialOffset , Stream , Subscription ,
135
+ } ;
0 commit comments