zero4rs 2.0.0

zero4rs is a powerful, pragmatic, and extremely fast web framework for Rust
Documentation
use deadpool::managed::{PoolConfig, QueueMode, Timeouts};
use deadpool_lapin::{lapin::Channel, Config};

use crate::core::rabbitmq::RabbitClient;

pub fn config() -> Config {
    Config {
        // vhost: %2f => /
        // RabbitMQ 的默认虚拟主机 `/` 和 `用户` 是在服务器启动时创建的。
        // 每个连接必须与单个虚拟主机关联。
        url: Some(String::from("amqp://guest:guest@localhost:5672/%2f")),
        pool: Some(PoolConfig {
            max_size: 100,
            timeouts: Timeouts::default(),
            queue_mode: QueueMode::Fifo,
        }),
        ..Default::default()
    }
}

pub async fn create_channel() -> anyhow::Result<Channel> {
    let pool = config().create_pool(Some(deadpool::Runtime::Tokio1));
    let connection = pool?.get().await?;
    let channel: Channel = connection.create_channel().await?;

    Ok(channel)
}

pub async fn create_client() -> anyhow::Result<RabbitClient> {
    Ok(RabbitClient {
        channel: create_channel().await?,
    })
}