Crates.io | cl-deadpool-lapin2 |
lib.rs | cl-deadpool-lapin2 |
version | 0.10.0 |
source | src |
created_at | 2022-02-23 12:41:27.998298 |
updated_at | 2022-02-23 12:41:27.998298 |
description | Dead simple async pool for lapin |
homepage | |
repository | https://github.com/bikeshedder/deadpool |
max_upload_size | |
id | 537847 |
size | 13,690 |
Deadpool is a dead simple async pool for connections and objects of any type.
This crate implements a deadpool
manager for lapin
.
Feature | Description | Extra dependencies | Default |
---|---|---|---|
rt_tokio_1 |
Enable support for tokio crate | deadpool/rt_tokio_1 |
yes |
rt_async-std_1 |
Enable support for async-std crate | deadpool/rt_async-std_1 |
no |
serde |
Enable support for serde crate | deadpool/serde , serde/derive |
no |
tokio-amqp
crateuse std::sync::Arc;
use deadpool_lapin::{Config, Manager, Pool, Runtime};
use deadpool_lapin::lapin::{
options::BasicPublishOptions,
BasicProperties,
};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut cfg = Config::default();
cfg.url = Some("amqp://127.0.0.1:5672/%2f".into());
let pool = cfg.create_pool(Some(Runtime::Tokio1))?;
for _ in 1..10 {
let mut connection = pool.get().await?;
let channel = connection.create_channel().await?;
channel.basic_publish(
"",
"hello",
BasicPublishOptions::default(),
b"hello from deadpool",
BasicProperties::default(),
).await?;
}
Ok(())
}
config
, dotenv
and tokio-amqp
crateuse std::sync::Arc;
use deadpool_lapin::Runtime;
use deadpool_lapin::lapin::{
options::BasicPublishOptions,
BasicProperties,
};
use dotenv::dotenv;
# use serde_1 as serde;
#[derive(Debug, serde::Deserialize)]
# #[serde(crate = "serde_1")]
struct Config {
#[serde(default)]
amqp: deadpool_lapin::Config
}
impl Config {
pub fn from_env() -> Result<Self, config::ConfigError> {
let mut cfg = config::Config::new();
cfg.merge(config::Environment::new().separator("__"))?;
cfg.try_into()
}
}
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
dotenv().ok();
let mut cfg = Config::from_env().unwrap();
let pool = cfg.amqp.create_pool(Some(Runtime::Tokio1)).unwrap();
for _ in 1..10 {
let mut connection = pool.get().await?;
let channel = connection.create_channel().await?;
channel.basic_publish(
"",
"hello",
BasicPublishOptions::default(),
b"hello from deadpool",
BasicProperties::default(),
).await?;
}
Ok(())
}
Licensed under either of
at your option.