Skip to content

Commit 76f7814

Browse files
Make message properties in IEventHubPublisher optional
1 parent 2cc50f5 commit 76f7814

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

src/Atc.Azure.Messaging/EventHub/EventHubPublisher.cs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public EventHubPublisher(EventHubProducerClient client)
1616

1717
public Task PublishAsync(
1818
object message,
19-
IDictionary<string, string> messageProperties,
19+
IDictionary<string, string>? messageProperties = null,
2020
CancellationToken cancellationToken = default)
2121
{
2222
return PerformPublishAsync(
@@ -27,17 +27,20 @@ public Task PublishAsync(
2727

2828
private Task PerformPublishAsync(
2929
string messageBody,
30-
IDictionary<string, string> messageProperties,
31-
CancellationToken cancellationToken)
30+
IDictionary<string, string>? messageProperties = null,
31+
CancellationToken cancellationToken = default)
3232
{
3333
var eventBody = Encoding.UTF8.GetBytes(messageBody);
3434
var eventData = new EventData(eventBody);
3535

36-
foreach (var property in messageProperties)
36+
if (messageProperties != null)
3737
{
38-
eventData.Properties.Add(
39-
property.Key,
40-
property.Value);
38+
foreach (var property in messageProperties)
39+
{
40+
eventData.Properties.Add(
41+
property.Key,
42+
property.Value);
43+
}
4144
}
4245

4346
return client.SendAsync(

src/Atc.Azure.Messaging/EventHub/IEventHubPublisher.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ public interface IEventHubPublisher : IAsyncDisposable
44
{
55
Task PublishAsync(
66
object message,
7-
IDictionary<string, string> messageProperties,
7+
IDictionary<string, string>? messageProperties = null,
88
CancellationToken cancellationToken = default);
99
}

0 commit comments

Comments
 (0)