1- use core:: fmt;
2- use std:: borrow:: Cow ;
3-
41use anyhow:: anyhow;
52use camino:: Utf8PathBuf ;
3+ use core:: fmt;
4+ use std:: borrow:: Cow ;
5+ use std:: time:: Duration ;
66use tedge_config:: auth_method:: AuthMethod ;
77use tedge_config:: HostPort ;
88use tedge_config:: TEdgeConfigLocation ;
@@ -43,6 +43,7 @@ pub struct BridgeConfig {
4343 pub connection_check_attempts : i32 ,
4444 pub auth_method : Option < AuthMethod > ,
4545 pub mosquitto_version : Option < String > ,
46+ pub keepalive_interval : Duration ,
4647}
4748
4849#[ derive( Debug , Eq , PartialEq , Clone , Copy ) ]
@@ -106,6 +107,11 @@ impl BridgeConfig {
106107 "bridge_attempt_unsubscribe {}" ,
107108 self . bridge_attempt_unsubscribe
108109 ) ?;
110+ writeln ! (
111+ writer,
112+ "keepalive_interval {}" ,
113+ self . keepalive_interval. as_secs( )
114+ ) ?;
109115
110116 writeln ! ( writer, "\n ### Topics" , ) ?;
111117 for topic in & self . topics {
@@ -212,6 +218,7 @@ mod test {
212218 connection_check_attempts : 1 ,
213219 auth_method : None ,
214220 mosquitto_version : None ,
221+ keepalive_interval : Duration :: from_secs ( 60 ) ,
215222 } ;
216223
217224 let mut serialized_config = Vec :: < u8 > :: new ( ) ;
@@ -239,6 +246,7 @@ notifications false
239246notifications_local_only false
240247notification_topic test_topic
241248bridge_attempt_unsubscribe false
249+ keepalive_interval 60
242250
243251### Topics
244252"# ,
@@ -282,6 +290,7 @@ bridge_attempt_unsubscribe false
282290 connection_check_attempts : 1 ,
283291 auth_method : None ,
284292 mosquitto_version : None ,
293+ keepalive_interval : Duration :: from_secs ( 60 ) ,
285294 } ;
286295 let mut serialized_config = Vec :: < u8 > :: new ( ) ;
287296 bridge. serialize ( & mut serialized_config) ?;
@@ -308,6 +317,7 @@ notifications false
308317notifications_local_only false
309318notification_topic test_topic
310319bridge_attempt_unsubscribe false
320+ keepalive_interval 60
311321
312322### Topics
313323"# ,
@@ -354,6 +364,7 @@ bridge_attempt_unsubscribe false
354364 connection_check_attempts : 1 ,
355365 auth_method : None ,
356366 mosquitto_version : None ,
367+ keepalive_interval : Duration :: from_secs ( 60 ) ,
357368 } ;
358369
359370 let mut buffer = Vec :: new ( ) ;
@@ -383,6 +394,7 @@ bridge_attempt_unsubscribe false
383394 expected. insert ( "notifications_local_only false" ) ;
384395 expected. insert ( "notification_topic test_topic" ) ;
385396 expected. insert ( "bridge_attempt_unsubscribe false" ) ;
397+ expected. insert ( "keepalive_interval 60" ) ;
386398
387399 expected. insert ( "topic messages/events/ out 1 az/ devices/alpha/" ) ;
388400 expected. insert ( "topic messages/devicebound/# in 1 az/ devices/alpha/" ) ;
@@ -426,6 +438,7 @@ bridge_attempt_unsubscribe false
426438 connection_check_attempts : 1 ,
427439 auth_method : None ,
428440 mosquitto_version : None ,
441+ keepalive_interval : Duration :: from_secs ( 60 ) ,
429442 } ;
430443
431444 let mut buffer = Vec :: new ( ) ;
@@ -454,6 +467,7 @@ bridge_attempt_unsubscribe false
454467 expected. insert ( "notifications_local_only false" ) ;
455468 expected. insert ( "notification_topic test_topic" ) ;
456469 expected. insert ( "bridge_attempt_unsubscribe false" ) ;
470+ expected. insert ( "keepalive_interval 60" ) ;
457471 expected. insert ( r#"topic inventory/managedObjects/update/# out 2 c8y/ """# ) ;
458472 expected. insert ( r#"topic measurement/measurements/create out 2 c8y/ """# ) ;
459473 assert_eq ! ( config_set, expected) ;
@@ -545,6 +559,7 @@ bridge_attempt_unsubscribe false
545559 connection_check_attempts : 1 ,
546560 auth_method : None ,
547561 mosquitto_version : None ,
562+ keepalive_interval : Duration :: from_secs ( 60 ) ,
548563 }
549564 }
550565}
0 commit comments