@@ -100,7 +100,7 @@ use tracing::trace;
100
100
use tracing:: warn;
101
101
102
102
const INTERNAL_ALARMS_TOPIC : & str = "c8y-internal/alarms/" ;
103
- const C8Y_JSON_MQTT_EVENTS_TOPIC : & str = "c8y/ event/events/create" ;
103
+ const C8Y_JSON_MQTT_EVENTS_TOPIC : & str = "event/events/create" ;
104
104
const TEDGE_AGENT_LOG_DIR : & str = "agent" ;
105
105
const CREATE_EVENT_SMARTREST_CODE : u16 = 400 ;
106
106
const DEFAULT_EVENT_TYPE : & str = "ThinEdgeEvent" ;
@@ -499,7 +499,10 @@ impl CumulocityConverter {
499
499
} else {
500
500
// If the message contains extra fields other than `text` and `time`, convert to Cumulocity JSON
501
501
let cumulocity_event_json = serde_json:: to_string ( & c8y_event) ?;
502
- let json_mqtt_topic = Topic :: new_unchecked ( C8Y_JSON_MQTT_EVENTS_TOPIC ) ;
502
+ let json_mqtt_topic = Topic :: new_unchecked ( & format ! (
503
+ "{}/{C8Y_JSON_MQTT_EVENTS_TOPIC}" ,
504
+ self . config. c8y_prefix
505
+ ) ) ;
503
506
Message :: new ( & json_mqtt_topic, cumulocity_event_json)
504
507
} ;
505
508
@@ -2396,6 +2399,30 @@ pub(crate) mod tests {
2396
2399
) ;
2397
2400
}
2398
2401
2402
+ #[ tokio:: test]
2403
+ async fn convert_event_with_custom_c8y_topic_prefix ( ) {
2404
+ let tmp_dir = TempTedgeDir :: new ( ) ;
2405
+ let mut config = c8y_converter_config ( & tmp_dir) ;
2406
+ let tedge_config = TEdgeConfig :: load_toml_str ( "service.ty = \" \" " ) ;
2407
+ config. service = tedge_config. service . clone ( ) ;
2408
+ config. c8y_prefix = "custom-topic" . into ( ) ;
2409
+
2410
+ let ( mut converter, _) = create_c8y_converter_from_config ( config) ;
2411
+ let event_topic = "te/device/main///e/click_event" ;
2412
+ let event_payload = r#"{ "text": "Someone clicked", "time": "2020-02-02T01:02:03+05:30" }"# ;
2413
+ let event_message = Message :: new ( & Topic :: new_unchecked ( event_topic) , event_payload) ;
2414
+
2415
+ let converted_events = converter. convert ( & event_message) . await ;
2416
+ assert_eq ! ( converted_events. len( ) , 1 ) ;
2417
+ let converted_event = converted_events. get ( 0 ) . unwrap ( ) ;
2418
+ assert_eq ! ( converted_event. topic. name, "custom-topic/s/us" ) ;
2419
+
2420
+ assert_eq ! (
2421
+ converted_event. payload_str( ) . unwrap( ) ,
2422
+ r#"400,click_event,"Someone clicked",2020-02-02T01:02:03+05:30"#
2423
+ ) ;
2424
+ }
2425
+
2399
2426
#[ tokio:: test]
2400
2427
async fn convert_event_with_extra_fields_to_c8y_json ( ) {
2401
2428
let tmp_dir = TempTedgeDir :: new ( ) ;
0 commit comments