|
1 | | -use rabbitmq_stream_client::Environment; |
| 1 | +use lapin::{Channel, Connection, ConnectionProperties}; |
2 | 2 | use std::sync::Arc; |
3 | 3 | use tokio::sync::Mutex; |
4 | 4 |
|
5 | | -pub type FlowQueue = Arc<Mutex<Box<Environment>>>; |
| 5 | +pub type FlowQueue = Arc<Mutex<Box<Connection>>>; |
6 | 6 |
|
7 | | -pub struct RedisConfiguration { |
8 | | - host: String, |
9 | | - port: u16, |
10 | | - username: String, |
11 | | - password: String, |
12 | | -} |
| 7 | +pub type FlowChannel = Arc<Mutex<Box<Channel>>>; |
13 | 8 |
|
14 | | -impl RedisConfiguration { |
15 | | - pub fn new(host: String, port: u16, username: String, password: String) -> Self { |
16 | | - Self { |
17 | | - host, |
18 | | - port, |
19 | | - username, |
20 | | - password, |
21 | | - } |
| 9 | +pub async fn connect(uri: &str) -> Connection { |
| 10 | + match Connection::connect(uri, ConnectionProperties::default()).await { |
| 11 | + Ok(env) => env, |
| 12 | + Err(error) => panic!("Cannot connect to redis instance! Reason: {:?}", error), |
22 | 13 | } |
23 | 14 | } |
24 | 15 |
|
25 | | -pub async fn init_rabbitmq(redis_configuration: RedisConfiguration) -> FlowQueue { |
26 | | - Arc::new(Mutex::new(Box::new(connect(redis_configuration).await))) |
27 | | -} |
| 16 | +pub async fn get_flow_channel(uri: &str) -> FlowChannel { |
| 17 | + let connection = connect(uri).await; |
28 | 18 |
|
29 | | -async fn connect(redis_configuration: RedisConfiguration) -> Environment { |
30 | | - match Environment::builder() |
31 | | - .host(&*redis_configuration.host) |
32 | | - .port(redis_configuration.port) |
33 | | - .username(&*redis_configuration.username) |
34 | | - .password(&*redis_configuration.password) |
35 | | - .build() |
36 | | - .await |
37 | | - { |
38 | | - Ok(env) => env, |
39 | | - Err(error) => panic!("Cannot connect to redis instance! Reason: {:?}", error), |
| 19 | + match connection.create_channel().await { |
| 20 | + Ok(channel) => Arc::new(Mutex::new(Box::new(channel))), |
| 21 | + Err(error) => panic!("Cannot create channel {:?}", error), |
40 | 22 | } |
41 | 23 | } |
0 commit comments