Crates.io | amqp-manager |
lib.rs | amqp-manager |
version | 1.3.1 |
source | src |
created_at | 2020-09-25 21:11:58.308957 |
updated_at | 2021-11-15 10:02:54.152551 |
description | Lapin wrapper that encapsulates the use of connections/channels and creation of amqp objects |
homepage | |
repository | https://github.com/adrianbenavides/amqp-manager |
max_upload_size | |
id | 292981 |
size | 74,508 |
Lapin wrapper that encapsulates the use of connections/channels and creation of amqp objects.
use amqp_manager::prelude::*;
use deadpool_lapin::{Config, Runtime};
use futures::FutureExt;
#[tokio::main]
async fn main() {
let pool = Config {
url: Some("amqp://guest:guest@127.0.0.1:5672//".to_string()),
..Default::default()
}
.create_pool(Some(Runtime::Tokio1))
.expect("Should create DeadPool instance");
let manager = AmqpManager::new(pool);
let session = manager
.create_session_with_confirm_select()
.await
.expect("Should create AmqpSession instance");
let create_queue_op = CreateQueue {
options: QueueDeclareOptions {
auto_delete: true,
..Default::default()
},
..Default::default()
};
let queue = session.create_queue(create_queue_op.clone()).await.expect("create_queue");
let confirmation = session
.publish_to_routing_key(PublishToRoutingKey {
routing_key: queue.name().as_str(),
payload: "Hello World".as_bytes(),
..Default::default()
})
.await
.expect("publish_to_queue");
assert!(confirmation.is_ack());
session
.create_consumer_with_delegate(
CreateConsumer {
queue_name: queue.name().as_str(),
..Default::default()
},
move |delivery: DeliveryResult| async {
if let Ok(Some((channel, delivery))) = delivery {
let payload = std::str::from_utf8(&delivery.data).unwrap();
assert_eq!(payload, "Hello World");
channel
.basic_ack(delivery.delivery_tag, BasicAckOptions::default())
.map(|_| ())
.await;
}
},
)
.await
.expect("create_consumer");
let queue = session.create_queue(create_queue_op.clone()).await.expect("create_queue");
assert_eq!(queue.message_count(), 0, "Messages has been consumed");
}
Please see the details of the lapin and deadpool crates about their requirements.