Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow setting custom properties in service_bus send_message() #1758

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions sdk/messaging_servicebus/src/service_bus/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,7 @@ use azure_core::{
CollectedResponse, HttpClient, Method, Request, StatusCode, Url,
};
use serde::{Deserialize, Serialize};
use std::{
str::FromStr,
time::Duration,
{ops::Add, sync::Arc},
};
use std::{collections::HashMap, ops::Add, str::FromStr, sync::Arc, time::Duration};
use time::OffsetDateTime;
use url::form_urlencoded::{self, Serializer};

Expand Down Expand Up @@ -315,6 +311,7 @@ impl FromStr for BrokerProperties {
pub struct SendMessageOptions {
pub content_type: Option<String>,
pub broker_properties: Option<SettableBrokerProperties>,
pub custom_properties: Option<HashMap<String, String>>,
}

impl headers::AsHeaders for SendMessageOptions {
Expand All @@ -334,6 +331,14 @@ impl headers::AsHeaders for SendMessageOptions {
));
}

if let Some(custom_properties) = &self.custom_properties {
headers.extend(
custom_properties
.iter()
.map(|(k, v)| (k.to_owned().into(), v.into())),
);
}

headers.into_iter()
}
}
Expand Down
21 changes: 21 additions & 0 deletions sdk/messaging_servicebus/tests/service_bus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,27 @@ async fn send_message_with_content_type() {
.expect("Failed to send message");
}

#[tokio::test]
async fn send_message_with_custom_property_test() {
let client = create_client().unwrap();
client
.send_message(
"hello, world!",
Some(SendMessageOptions {
custom_properties: Some(
std::collections::HashMap::from([(
"custom_property_key".into(),
"custom_property_value".into(),
)])
.into(),
),
..Default::default()
}),
)
.await
.expect("Failed to send message");
}

#[tokio::test]
async fn receive_and_delete_message_test() {
let client = create_client().unwrap();
Expand Down