use deadpool::managed::{PoolConfig, QueueMode, Timeouts};
use deadpool_lapin::{lapin::Channel, Config};
use crate::core::rabbitmq::RabbitClient;
pub fn config() -> Config {
Config {
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?,
})
}