Skip to content

Commit 2b32f8c

Browse files
committed
feat: added adjusted connection functions
1 parent 5c1e43c commit 2b32f8c

File tree

2 files changed

+15
-31
lines changed

2 files changed

+15
-31
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,6 @@
88
/dataSources.local.xml
99
.idea
1010
./target
11-
.target
11+
.target
12+
13+
target

src/flow_queue/connection.rs

Lines changed: 12 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,23 @@
1-
use rabbitmq_stream_client::Environment;
1+
use lapin::{Channel, Connection, ConnectionProperties};
22
use std::sync::Arc;
33
use tokio::sync::Mutex;
44

5-
pub type FlowQueue = Arc<Mutex<Box<Environment>>>;
5+
pub type FlowQueue = Arc<Mutex<Box<Connection>>>;
66

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>>>;
138

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),
2213
}
2314
}
2415

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;
2818

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),
4022
}
4123
}

0 commit comments

Comments
 (0)