lapin/lib.rs
1#![warn(rust_2018_idioms)]
2
3//! lapin
4//!
5//! This project follows the AMQP 0.9.1 specifications, targeting especially RabbitMQ.
6//!
7//! The main access point is the [`Channel`], which contains the individual
8//! AMQP methods. As to the AMQP specification, one TCP [`Connection`] can contain
9//! multiple channels.
10//!
11//! ## Feature switches
12//!
13//! * `codegen`: generate code instead of using pregenerated one
14//! * `native-tls`: enable amqps support through native-tls (preferred over rustls when set)
15//! * `openssl`: enable amqps support through openssl (preferred over rustls when set)
16//! * `rustls` (*default*): enable amqps support through rustls (uses rustls-native-certs by default)
17//! * `rustls-native-certs`: same as rustls, be ensure we'll still use rustls-native-certs even if the default for rustls changes
18//! * `rustls-webpki-roots-certs`: same as rustls but using webkit-roots instead of rustls-native-certs
19//!
20//! ## Example
21//!
22//! ```rust,no_run
23//! use async_rs::traits::*;
24//! use futures_lite::stream::StreamExt;
25//! use lapin::{
26//! options::*, Confirmation, types::FieldTable, BasicProperties, Connection,
27//! ConnectionProperties, Result,
28//! };
29//! use tracing::info;
30//!
31//! fn main() -> Result<()> {
32//! if std::env::var("RUST_LOG").is_err() {
33//! unsafe { std::env::set_var("RUST_LOG", "info") };
34//! }
35//!
36//! tracing_subscriber::fmt::init();
37//!
38//! let addr = std::env::var("AMQP_ADDR").unwrap_or_else(|_| "amqp://127.0.0.1:5672/%2f".into());
39//! let runtime = lapin::runtime::default_runtime()?;
40//!
41//! runtime.clone().block_on(async move {
42//! let conn = Connection::connect_with_runtime(
43//! &addr,
44//! ConnectionProperties::default(),
45//! runtime.clone(),
46//! )
47//! .await?;
48//!
49//! info!("CONNECTED");
50//!
51//! let channel_a = conn.create_channel().await?;
52//! let channel_b = conn.create_channel().await?;
53//!
54//! let queue = channel_a
55//! .queue_declare(
56//! "hello".into(),
57//! QueueDeclareOptions::default(),
58//! FieldTable::default(),
59//! )
60//! .await?;
61//!
62//! info!(?queue, "Declared queue");
63//!
64//! let mut consumer = channel_b
65//! .basic_consume(
66//! "hello".into(),
67//! "my_consumer".into(),
68//! BasicConsumeOptions::default(),
69//! FieldTable::default(),
70//! )
71//! .await?;
72//! runtime.spawn(async move {
73//! info!("will consume");
74//! while let Some(delivery) = consumer.next().await {
75//! let delivery = delivery.expect("error in consumer");
76//! delivery
77//! .ack(BasicAckOptions::default())
78//! .await
79//! .expect("ack");
80//! }
81//! });
82//!
83//! let payload = b"Hello world!";
84//!
85//! loop {
86//! let confirm = channel_a
87//! .basic_publish(
88//! "".into(),
89//! "hello".into(),
90//! BasicPublishOptions::default(),
91//! payload,
92//! BasicProperties::default(),
93//! )
94//! .await?
95//! .await?;
96//! assert_eq!(confirm, Confirmation::NotRequested);
97//! }
98//! })
99//! }
100//! ```
101//! [`Channel`]: ./struct.Channel.html
102//! [`Connection`]: ./struct.Connection.html
103
104pub use amq_protocol::{
105 protocol::{self, BasicProperties},
106 tcp::{self, AsyncTcpStream},
107 types, uri,
108};
109
110pub use acker::Acker;
111pub use channel::{Channel, options};
112pub use channel_status::{ChannelState, ChannelStatus};
113pub use configuration::Configuration;
114pub use connection::{Connect, Connection};
115pub use connection_builder::{ConnectionBuilder, DefaultConnectionBuilder};
116pub use connection_properties::ConnectionProperties;
117pub use connection_status::{ConnectionState, ConnectionStatus};
118pub use consumer::{Consumer, ConsumerDelegate};
119pub use error::{Error, ErrorKind, Result};
120pub use events::Event;
121pub use exchange::ExchangeKind;
122pub use publisher_confirm::Confirmation;
123pub use queue::Queue;
124
125pub mod auth;
126pub mod message;
127pub mod runtime;
128
129use promise::{Promise, PromiseResolver};
130
131mod acker;
132mod acknowledgement;
133mod basic_get_delivery;
134mod buffer;
135mod channel;
136mod channel_closer;
137mod channel_receiver_state;
138mod channel_recovery_context;
139mod channel_status;
140mod channels;
141mod configuration;
142mod connection;
143mod connection_builder;
144mod connection_closer;
145mod connection_properties;
146mod connection_status;
147mod consumer;
148mod consumer_canceler;
149mod consumer_status;
150mod consumers;
151mod error;
152mod error_holder;
153mod events;
154mod exchange;
155mod frames;
156mod future;
157mod heartbeat;
158mod id_sequence;
159mod internal_rpc;
160mod io_loop;
161mod killswitch;
162mod notifier;
163mod parsing;
164mod promise;
165mod publisher_confirm;
166mod queue;
167mod registry;
168mod returned_messages;
169mod secret_update;
170mod socket_state;
171mod thread;
172mod topology;
173mod wakers;