@@ -326,7 +326,7 @@ impl FromPeers {
326
326
match message {
327
327
PublishOrSubscribe :: Publish ( message) => {
328
328
tracing:: debug!( target: "MQTT pub" , "{message}" ) ;
329
- SinkExt :: send ( outgoing_mqtt, message)
329
+ SinkExt :: send ( outgoing_mqtt, message)
330
330
. await
331
331
. map_err ( Box :: new) ?;
332
332
}
@@ -365,18 +365,29 @@ impl FromPeers {
365
365
client. unsubscribe_many ( diff. unsubscribe ) . await . unwrap ( ) ;
366
366
}
367
367
} ) ;
368
- let dynamic_connection_config = self . base_config . clone ( ) . with_subscriptions ( tf) ;
369
- let mut sender = tx_to_peers. clone ( ) ;
370
- tokio:: spawn ( async move {
371
- let mut conn = mqtt_channel:: Connection :: new ( & dynamic_connection_config) . await . unwrap ( ) ;
372
- while let Ok ( msg) = tokio:: time:: timeout ( Duration :: from_secs ( 10 ) , conn. received . next ( ) ) . await {
373
- if let Some ( msg) = msg {
374
- if msg. retain {
375
- SinkExt :: send ( & mut sender, ( request. client_id , msg) ) . await . unwrap ( ) ;
368
+ if !tf. is_empty ( ) {
369
+ let dynamic_connection_config =
370
+ self . base_config . clone ( ) . with_subscriptions ( tf) ;
371
+ let mut sender = tx_to_peers. clone ( ) ;
372
+ tokio:: spawn ( async move {
373
+ let mut conn =
374
+ mqtt_channel:: Connection :: new ( & dynamic_connection_config)
375
+ . await
376
+ . unwrap ( ) ;
377
+ while let Ok ( msg) =
378
+ tokio:: time:: timeout ( Duration :: from_secs ( 10 ) , conn. received . next ( ) )
379
+ . await
380
+ {
381
+ if let Some ( msg) = msg {
382
+ if msg. retain {
383
+ SinkExt :: send ( & mut sender, ( request. client_id , msg) )
384
+ . await
385
+ . unwrap ( ) ;
386
+ }
376
387
}
377
388
}
378
- }
379
- } ) ;
389
+ } ) ;
390
+ }
380
391
}
381
392
}
382
393
}
@@ -510,9 +521,13 @@ impl Actor for MqttActor {
510
521
tokio:: spawn ( async move { self . trie_service . run ( ) . await } ) ;
511
522
512
523
tedge_utils:: futures:: select (
513
- self . from_peers
514
- . relay_messages_to ( & mut mqtt_client. published , & mut to_peer, mqtt_client. subscriptions ) ,
515
- self . to_peers . relay_messages_from ( & mut mqtt_client. received , & mut from_peer) ,
524
+ self . from_peers . relay_messages_to (
525
+ & mut mqtt_client. published ,
526
+ & mut to_peer,
527
+ mqtt_client. subscriptions ,
528
+ ) ,
529
+ self . to_peers
530
+ . relay_messages_from ( & mut mqtt_client. received , & mut from_peer) ,
516
531
)
517
532
. await
518
533
}
@@ -624,12 +639,12 @@ mod unit_tests {
624
639
id: 0
625
640
) )
626
641
. await ;
627
-
642
+
628
643
actor
629
644
. subscribe_client
630
645
. assert_unsubscribed_from ( [ "a/b" . into ( ) ] )
631
646
. await ;
632
-
647
+
633
648
actor. close ( ) . await ;
634
649
}
635
650
@@ -752,9 +767,15 @@ mod unit_tests {
752
767
let subscribe_client = MockSubscriberOps :: default ( ) ;
753
768
let from_peers = {
754
769
let client = subscribe_client. clone ( ) ;
755
- tokio:: spawn ( async move { fp. relay_messages_to ( & mut outgoing_mqtt, & mut tx, client) . await } )
770
+ tokio:: spawn ( async move {
771
+ fp. relay_messages_to ( & mut outgoing_mqtt, & mut tx, client)
772
+ . await
773
+ } )
756
774
} ;
757
- let to_peers = tokio:: spawn ( async move { tp. relay_messages_from ( & mut incoming_messages, & mut rx) . await } ) ;
775
+ let to_peers = tokio:: spawn ( async move {
776
+ tp. relay_messages_from ( & mut incoming_messages, & mut rx)
777
+ . await
778
+ } ) ;
758
779
759
780
Self {
760
781
subscribe_client,
@@ -771,7 +792,7 @@ mod unit_tests {
771
792
772
793
/// Closes the channels associated with this actor and waits for both
773
794
/// loops to finish executing
774
- ///
795
+ ///
775
796
/// This allows the `SubscriberOps::drop` implementation to reliably
776
797
/// flag any unasserted communication
777
798
pub async fn close ( mut self ) {
0 commit comments