Skip to content

Commit 631de99

Browse files
authored
Merge pull request #3862 from albinsuresh/feat/mqtt-service-as-primary
feat: single connection to either mqtt service or core mqtt
2 parents 661d55d + e772f1c commit 631de99

File tree

15 files changed

+278
-440
lines changed

15 files changed

+278
-440
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
pub const MQTT_CORE_TLS_PORT: u16 = 8883;
2+
pub const MQTT_SERVICE_TLS_PORT: u16 = 9883;

crates/common/tedge_config/src/tedge_toml/models/host_port.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,12 @@ impl<const P: u16> HostPort<P> {
5858
pub fn port(&self) -> Port {
5959
self.port
6060
}
61+
62+
/// Sets the port for this HostPort and updates the stored input string as well
63+
pub fn set_port(&mut self, port: u16) {
64+
self.port = Port(port);
65+
self.input = format!("{}:{}", self.hostname, self.port);
66+
}
6167
}
6268

6369
impl<const P: u16> From<HostPort<P>> for String {

crates/common/tedge_config/src/tedge_toml/models/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
pub mod apt_config;
22
pub mod auth_method;
33
pub mod auto;
4+
pub mod c8y;
45
pub mod c8y_software_management;
56
pub mod connect_url;
67
pub mod cryptoki;
@@ -24,10 +25,10 @@ use strum::Display;
2425

2526
pub const HTTPS_PORT: u16 = 443;
2627
pub const MQTT_TLS_PORT: u16 = 8883;
27-
pub const MQTT_SVC_TLS_PORT: u16 = 9883;
2828

2929
pub use self::apt_config::*;
3030
pub use self::auto::*;
31+
pub use self::c8y::*;
3132
pub use self::c8y_software_management::*;
3233
pub use self::connect_url::*;
3334
pub use self::cryptoki::Cryptoki;

crates/common/tedge_config/src/tedge_toml/tedge_config.rs

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ use super::models::SoftwareManagementApiFlag;
2020
use super::models::TemplatesSet;
2121
use super::models::TopicPrefix;
2222
use super::models::HTTPS_PORT;
23-
use super::models::MQTT_SVC_TLS_PORT;
2423
use super::models::MQTT_TLS_PORT;
2524
use super::tedge_config_location::TEdgeConfigLocation;
2625
use crate::models::AbsolutePath;
@@ -475,20 +474,9 @@ define_tedge_config! {
475474
#[tedge_config(example = "true", default(value = false))]
476475
enabled: bool,
477476

478-
/// MQTT service endpoint for the Cumulocity tenant, with optional port.
479-
#[tedge_config(example = "mqtt.your-tenant.cumulocity.com:9883")]
480-
#[tedge_config(default(from_optional_key = "c8y.mqtt"))]
481-
url: HostPort<MQTT_SVC_TLS_PORT>,
482-
483-
/// The topic prefix that will be used for the Cumulocity MQTT service endpoint connection.
484-
/// For instance, if set to "c8y-mqtt", then messages published to `c8y-mqtt/xyz`
485-
/// will be forwarded to the MQTT service endpoint on the `xyz` topic
486-
#[tedge_config(example = "c8y-mqtt", default(function = "c8y_mqtt_service_topic_prefix"))]
487-
topic_prefix: TopicPrefix,
488-
489477
/// Set of MQTT topics the bridge should subscribe to on the Cumulocity MQTT service endpoint
490478
#[tedge_config(example = "incoming/topic,another/topic,test/topic")]
491-
#[tedge_config(default(value = "$demo/$error"))]
479+
#[tedge_config(default(function = "TemplatesSet::default"))]
492480
topics: TemplatesSet,
493481
}
494482
},
@@ -1220,16 +1208,6 @@ fn c8y_topic_prefix() -> TopicPrefix {
12201208
TopicPrefix::try_new("c8y").unwrap()
12211209
}
12221210

1223-
fn c8y_mqtt_service_topic_prefix() -> TopicPrefix {
1224-
TopicPrefix::try_new("c8y-mqtt").unwrap()
1225-
}
1226-
1227-
impl From<HostPort<MQTT_TLS_PORT>> for HostPort<MQTT_SVC_TLS_PORT> {
1228-
fn from(value: HostPort<MQTT_TLS_PORT>) -> Self {
1229-
HostPort::try_from(value.host().to_string()).expect("Source hostname must have been valid")
1230-
}
1231-
}
1232-
12331211
fn az_topic_prefix() -> TopicPrefix {
12341212
TopicPrefix::try_new("az").unwrap()
12351213
}

crates/common/tedge_config/src/tedge_toml/tedge_config/append_remove.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ impl_append_remove_for_single_value!(
4141
EntityTopicId,
4242
HostPort<HTTPS_PORT>,
4343
HostPort<MQTT_TLS_PORT>,
44-
HostPort<MQTT_SVC_TLS_PORT>,
4544
bool,
4645
IpAddr,
4746
u16,

crates/core/tedge/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ mockall = { workspace = true }
7777
mockito = { workspace = true }
7878
mqtt_tests = { workspace = true }
7979
predicates = { workspace = true }
80+
pretty_assertions = { workspace = true }
8081
rcgen = { workspace = true }
8182
tedge_config = { workspace = true, features = ["test"] }
8283
tedge_test_utils = { workspace = true }

0 commit comments

Comments
 (0)