Skip to content

Commit c4dbaf6

Browse files
authored
Merge pull request #37 from niwaniwa/niwaniwa/feature/mqtt-address
Niwaniwa/feature/mqtt address
2 parents 944e967 + 5f7226a commit c4dbaf6

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

docker-compose.yml

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ services:
3232
- 8080:8080
3333
environment:
3434
DATABASE_URL: postgres://sakura:password@db:5432/sakura
35+
MQTT_URL: mqtt://mqtt:1883
3536
networks:
3637
- sakura-internal
3738
- sakura-external

src/infrastructures/mqtt_connection.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1+
use std::collections::HashMap;
2+
use std::env;
3+
14
use crate::domain::repository::mqtt::client::MqttClientRepository;
25
use crate::infrastructures::config::mqtt_config::MqttConfig;
36
use crate::infrastructures::iot::mqtt_client::MqttClient;
47
use crate::server::connection::RequestContext;
58

6-
use std::collections::HashMap;
7-
use std::env;
8-
99
pub struct MqttConnection {
1010
cfg: MqttConfig,
1111
}
@@ -16,9 +16,10 @@ impl MqttConnection {
1616
}
1717

1818
pub fn mqtt_client_repository(&self) -> impl MqttClientRepository {
19+
let address = env::var("MQTT_URL").expect("MQTT_URL is not set");
1920
let host = env::args()
2021
.nth(1)
21-
.unwrap_or_else(|| "mqtt://".to_string() + &self.cfg.address);
22+
.unwrap_or_else(|| "mqtt://".to_string() + &address);
2223

2324
let create_opts = paho_mqtt::CreateOptionsBuilder::new()
2425
.server_uri(host)

src/server/connection.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ pub struct RequestContext {
2020
impl RequestContext {
2121
pub fn new() -> RequestContext {
2222
dotenv().ok();
23-
let db_url = env::var("DATABASE_URL").expect("DATABASE_URL i not set");
23+
let db_url = env::var("DATABASE_URL").expect("DATABASE_URL is not set");
2424
let manager = ConnectionManager::<PgConnection>::new(db_url);
2525
let pool = Pool::builder()
2626
.build(manager)

0 commit comments

Comments
 (0)