Skip to content

Commit

Permalink
Allow setting custom properties in service_bus send_message()
Browse files Browse the repository at this point in the history
  • Loading branch information
bryanpendleton authored and gitbutler-client committed Aug 19, 2024
1 parent 6409e82 commit c6f30c3
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
5 changes: 5 additions & 0 deletions sdk/messaging_servicebus/src/service_bus/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ impl FromStr for BrokerProperties {
pub struct SendMessageOptions {
pub content_type: Option<String>,
pub broker_properties: Option<SettableBrokerProperties>,
pub custom_properties: Option<headers::Headers>,
}

impl headers::AsHeaders for SendMessageOptions {
Expand All @@ -333,6 +334,10 @@ impl headers::AsHeaders for SendMessageOptions {
serde_json::to_string(broker_properties).unwrap().into(),
));
}

if let Some(custom_properties) = &self.custom_properties {
headers.extend(custom_properties.clone().into_iter());
}

headers.into_iter()
}
Expand Down
19 changes: 19 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,25 @@ 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

0 comments on commit c6f30c3

Please sign in to comment.