Skip to content

Commit b16e879

Browse files
Allow setting custom properties in service_bus send_message() (#1758)
* Allow setting custom properties in service_bus send_message() * Format corrections.
1 parent 6409e82 commit b16e879

File tree

2 files changed

+31
-5
lines changed

2 files changed

+31
-5
lines changed

sdk/messaging_servicebus/src/service_bus/mod.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,7 @@ use azure_core::{
1515
CollectedResponse, HttpClient, Method, Request, StatusCode, Url,
1616
};
1717
use serde::{Deserialize, Serialize};
18-
use std::{
19-
str::FromStr,
20-
time::Duration,
21-
{ops::Add, sync::Arc},
22-
};
18+
use std::{collections::HashMap, ops::Add, str::FromStr, sync::Arc, time::Duration};
2319
use time::OffsetDateTime;
2420
use url::form_urlencoded::{self, Serializer};
2521

@@ -315,6 +311,7 @@ impl FromStr for BrokerProperties {
315311
pub struct SendMessageOptions {
316312
pub content_type: Option<String>,
317313
pub broker_properties: Option<SettableBrokerProperties>,
314+
pub custom_properties: Option<HashMap<String, String>>,
318315
}
319316

320317
impl headers::AsHeaders for SendMessageOptions {
@@ -334,6 +331,14 @@ impl headers::AsHeaders for SendMessageOptions {
334331
));
335332
}
336333

334+
if let Some(custom_properties) = &self.custom_properties {
335+
headers.extend(
336+
custom_properties
337+
.iter()
338+
.map(|(k, v)| (k.to_owned().into(), v.into())),
339+
);
340+
}
341+
337342
headers.into_iter()
338343
}
339344
}

sdk/messaging_servicebus/tests/service_bus.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,27 @@ async fn send_message_with_content_type() {
5050
.expect("Failed to send message");
5151
}
5252

53+
#[tokio::test]
54+
async fn send_message_with_custom_property_test() {
55+
let client = create_client().unwrap();
56+
client
57+
.send_message(
58+
"hello, world!",
59+
Some(SendMessageOptions {
60+
custom_properties: Some(
61+
std::collections::HashMap::from([(
62+
"custom_property_key".into(),
63+
"custom_property_value".into(),
64+
)])
65+
.into(),
66+
),
67+
..Default::default()
68+
}),
69+
)
70+
.await
71+
.expect("Failed to send message");
72+
}
73+
5374
#[tokio::test]
5475
async fn receive_and_delete_message_test() {
5576
let client = create_client().unwrap();

0 commit comments

Comments
 (0)