File tree Expand file tree Collapse file tree 2 files changed +25
-2
lines changed
rust/azure_iot_operations_mqtt/src Expand file tree Collapse file tree 2 files changed +25
-2
lines changed Original file line number Diff line number Diff line change @@ -267,6 +267,7 @@ pub fn client(
267267 connection_settings : MqttConnectionSettings ,
268268 channel_capacity : usize ,
269269 manual_ack : bool ,
270+ connection_user_properties : Vec < ( String , String ) > ,
270271) -> Result < ( rumqttc:: v5:: AsyncClient , rumqttc:: v5:: EventLoop ) , MqttAdapterError > {
271272 // NOTE: channel capacity for AsyncClient must be less than usize::MAX - 1 due to (presumably) a bug.
272273 // It panics if you set MAX, although MAX - 1 is fine.
@@ -277,6 +278,12 @@ pub fn client(
277278 }
278279 let mut mqtt_options: rumqttc:: v5:: MqttOptions = connection_settings. try_into ( ) ?;
279280 mqtt_options. set_manual_acks ( manual_ack) ;
281+
282+ // Add any provided user properties
283+ let mut existing_props = mqtt_options. user_properties ( ) ;
284+ existing_props. extend ( connection_user_properties) ;
285+ mqtt_options. set_user_properties ( existing_props) ;
286+
280287 Ok ( rumqttc:: v5:: AsyncClient :: new (
281288 mqtt_options,
282289 channel_capacity,
Original file line number Diff line number Diff line change @@ -58,6 +58,9 @@ pub struct SessionOptions {
5858 /// Maximum number of queued outgoing messages not yet accepted by the MQTT Session
5959 #[ builder( default = "100" ) ]
6060 pub outgoing_max : usize ,
61+ /// Indicates if the Session should use features specific for use with the AIO MQTT Broker
62+ #[ builder( default = true ) ]
63+ pub aio_broker_features : bool ,
6164}
6265
6366impl Session {
@@ -68,8 +71,21 @@ impl Session {
6871 pub fn new ( options : SessionOptions ) -> Result < Self , SessionConfigError > {
6972 let client_id = options. connection_settings . client_id . clone ( ) ;
7073 let sat_file = options. connection_settings . sat_file . clone ( ) ;
71- let ( client, event_loop) =
72- adapter:: client ( options. connection_settings , options. outgoing_max , true ) ?;
74+
75+ // Add AIO metric to user properties when using AIO MQTT broker features
76+ // TODO: consider user properties from being supported on SessionOptions or ConnectionSettings
77+ let user_properties = if options. aio_broker_features {
78+ vec ! [ ( "metriccategory" . into( ) , "aiosdk-rust" . into( ) ) ]
79+ } else {
80+ vec ! [ ]
81+ } ;
82+
83+ let ( client, event_loop) = adapter:: client (
84+ options. connection_settings ,
85+ options. outgoing_max ,
86+ true ,
87+ user_properties,
88+ ) ?;
7389 Ok ( Session ( session:: Session :: new_from_injection (
7490 client,
7591 event_loop,
You can’t perform that action at this time.
0 commit comments