rabbitmq_stream_client/
lib.rs

1//! rabbitmq-stream-client
2//!
3//! Experimental Rust client for [RabbitMQ Stream](https://github.com/rabbitmq/rabbitmq-server/tree/master/deps/rabbitmq_stream)
4//!
5//! The main access point is [`Environment`], which is used to connect to a node.
6//!
7//! ## Example
8//!
9//! ### Building the environment
10//!
11//! ```rust,no_run
12//! # async fn doc_fn() -> Result<(), Box<dyn std::error::Error>> {
13//! use rabbitmq_stream_client::Environment;
14//!
15//! let environment = Environment::builder().build().await?;
16//! # Ok(())
17//! # }
18//! ```
19//!
20//! For more connection options check [`EnvironmentBuilder`]
21//!
22//! ### Publishing messages
23//!
24//! ```rust,no_run
25//! # async fn doc_fn() -> Result<(), Box<dyn std::error::Error>> {
26//! use rabbitmq_stream_client::{Environment, types::Message};
27//!
28//! let environment = Environment::builder().build().await?;
29//! let producer = environment.producer().build("mystream").await?;
30//!
31//! for i in 0..10 {
32//!     producer
33//!         .send_with_confirm(Message::builder().body(format!("message{}", i)).build())
34//!         .await?;
35//! }
36//!
37//! producer.close().await?;
38//!
39//! # Ok(())
40//! # }
41//! ```
42//! For more producer options check [`ProducerBuilder`]
43//!
44//! ### Consuming messages
45//!
46//! ```rust,no_run
47//! # async fn doc_fn() -> Result<(), Box<dyn std::error::Error>> {
48//! use rabbitmq_stream_client::{Environment};
49//! use futures::StreamExt;
50//! use tokio::task;
51//! use tokio::time::{sleep, Duration};
52//!
53//! let environment = Environment::builder().build().await?;
54//! let mut consumer = environment.consumer().build("mystream").await?;
55//!
56//!
57//! let handle = consumer.handle();
58//! task::spawn(async move {
59//!     while let Some(delivery) = consumer.next().await {
60//!         println!("Got message {:?}",delivery);
61//!     }
62//! });
63//!
64//! // wait 10 second and then close the consumer
65//! sleep(Duration::from_secs(10)).await;
66//!
67//! handle.close().await?;
68//!
69//! # Ok(())
70//! # }
71//! ```
72//! For more consumer options check [`ConsumerBuilder`]
73
74mod byte_capacity;
75mod client;
76mod consumer;
77mod environment;
78pub mod error;
79mod offset_specification;
80mod producer;
81mod stream_creator;
82mod superstream;
83mod superstream_consumer;
84mod superstream_producer;
85
86pub type RabbitMQStreamResult<T> = Result<T, error::ClientError>;
87
88pub use crate::client::{
89    Client, ClientOptions, MetricsCollector, TlsConfiguration, TlsConfigurationBuilder,
90};
91
92pub use crate::consumer::{
93    Consumer, ConsumerBuilder, ConsumerHandle, FilterConfiguration, MessageContext,
94};
95pub use crate::environment::{Environment, EnvironmentBuilder};
96pub use crate::producer::{
97    ConfirmationStatus, Dedup, NoDedup, OnClosed, Producer, ProducerBuilder,
98};
99pub mod types {
100
101    pub use crate::byte_capacity::ByteCapacity;
102    pub use crate::client::{Broker, MessageResult, StreamMetadata};
103    pub use crate::consumer::{Delivery, MessageContext};
104    pub use crate::offset_specification::OffsetSpecification;
105    pub use crate::stream_creator::LeaderLocator;
106    pub use crate::stream_creator::StreamCreator;
107    pub use crate::superstream::HashRoutingMurmurStrategy;
108    pub use crate::superstream::RoutingKeyRoutingStrategy;
109    pub use crate::superstream::RoutingStrategy;
110    pub use crate::superstream_consumer::SuperStreamConsumer;
111    pub use crate::superstream_producer::SuperStreamProducer;
112    pub use rabbitmq_stream_protocol::message::Message;
113    pub use rabbitmq_stream_protocol::{Response, ResponseCode, ResponseKind};
114
115    pub use rabbitmq_stream_protocol::message::{
116        AnnonationKey, ApplicationProperties, DeliveryAnnotations, Footer, Header, Map, Properties,
117        SimpleValue, Value,
118    };
119}