13 releases (8 breaking)

0.12.1 May 4, 2024
0.12.0 Mar 31, 2024
0.11.0 Sep 26, 2023
0.10.0 Feb 23, 2022
0.0.0 Dec 3, 2019

#1020 in Asynchronous

Download history 1469/week @ 2024-09-18 1909/week @ 2024-09-25 1809/week @ 2024-10-02 1616/week @ 2024-10-09 1626/week @ 2024-10-16 1958/week @ 2024-10-23 2021/week @ 2024-10-30 2543/week @ 2024-11-06 2113/week @ 2024-11-13 1869/week @ 2024-11-20 2229/week @ 2024-11-27 1795/week @ 2024-12-04 1671/week @ 2024-12-11 1353/week @ 2024-12-18 869/week @ 2024-12-25 1428/week @ 2025-01-01

5,708 downloads per month
Used in 5 crates

MIT/Apache

86KB
1.5K SLoC

Deadpool for Lapin Latest Version Unsafe forbidden Rust 1.75+

Deadpool is a dead simple async pool for connections and objects of any type.

This crate implements a deadpool manager for lapin.

Features

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

Example with tokio-amqp crate

use 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(())
}

Example with config, dotenvy and tokio-amqp crate

use std::sync::Arc;

use deadpool_lapin::Runtime;
use deadpool_lapin::lapin::{
    options::BasicPublishOptions,
    BasicProperties,
};
use dotenvy::dotenv;

#[derive(Debug, serde::Deserialize)]
struct Config {
    #[serde(default)]
    amqp: deadpool_lapin::Config
}

impl Config {
    pub fn from_env() -> Result<Self, config::ConfigError> {
         config::Config::builder()
            .add_source(config::Environment::default().separator("__"))
            .build()?
            .try_deserialize()
    }
}

#[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(())
}

License

Licensed under either of

at your option.

Dependencies

~10–21MB
~317K SLoC