From a371edd26841b2c6f5320a7dfe863127e14ad230 Mon Sep 17 00:00:00 2001 From: Chris Walsh Date: Mon, 6 Jan 2025 16:38:22 -0500 Subject: [PATCH] attach metadata to each individual message in bulkpublish if it exists Signed-off-by: Chris Walsh --- src/Dapr.Client/DaprClientGrpc.cs | 6 ++++ .../BulkPublishEventApiTest.cs | 28 +++++++++++++++---- 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/src/Dapr.Client/DaprClientGrpc.cs b/src/Dapr.Client/DaprClientGrpc.cs index 40df4767c..1f53f216c 100644 --- a/src/Dapr.Client/DaprClientGrpc.cs +++ b/src/Dapr.Client/DaprClientGrpc.cs @@ -219,6 +219,12 @@ events[counter] is CloudEvent : Constants.ContentTypeApplicationJson, Metadata = { }, }; + + if (metadata != null) + { + entry.Metadata.Add(metadata); + } + envelope.Entries.Add(entry); entryMap.Add(counter.ToString(), new BulkPublishEntry( entry.EntryId, events[counter], entry.ContentType, entry.Metadata)); diff --git a/test/Dapr.Client.Test/BulkPublishEventApiTest.cs b/test/Dapr.Client.Test/BulkPublishEventApiTest.cs index 74d617a20..75e7df05b 100644 --- a/test/Dapr.Client.Test/BulkPublishEventApiTest.cs +++ b/test/Dapr.Client.Test/BulkPublishEventApiTest.cs @@ -106,7 +106,11 @@ await daprClient.BulkPublishEventAsync(TestPubsubName, TestTopicName, bulkPublis firstEntry.ContentType.Should().Be(TestContentType); firstEntry.Event.ToStringUtf8().Should() .Be(JsonSerializer.Serialize(bulkPublishData[0], client.InnerClient.JsonSerializerOptions)); - firstEntry.Metadata.Should().BeEmpty(); + firstEntry.Metadata.Count.Should().Be(2); + firstEntry.Metadata.Keys.Contains("key1").Should().BeTrue(); + firstEntry.Metadata.Keys.Contains("key2").Should().BeTrue(); + firstEntry.Metadata["key1"].Should().Be("value1"); + firstEntry.Metadata["key2"].Should().Be("value2"); var secondEntry = envelope.Entries[1]; @@ -114,8 +118,12 @@ await daprClient.BulkPublishEventAsync(TestPubsubName, TestTopicName, bulkPublis secondEntry.ContentType.Should().Be(TestContentType); secondEntry.Event.ToStringUtf8().Should() .Be(JsonSerializer.Serialize(bulkPublishData[1], client.InnerClient.JsonSerializerOptions)); - secondEntry.Metadata.Should().BeEmpty(); - + secondEntry.Metadata.Count.Should().Be(2); + secondEntry.Metadata.Keys.Contains("key1").Should().BeTrue(); + secondEntry.Metadata.Keys.Contains("key2").Should().BeTrue(); + secondEntry.Metadata["key1"].Should().Be("value1"); + secondEntry.Metadata["key2"].Should().Be("value2"); + // Create Response & Respond var response = new Autogenerated.BulkPublishResponse { @@ -201,7 +209,11 @@ await daprClient.BulkPublishEventAsync(TestPubsubName, TestTopicName, bulkPublis firstEntry.ContentType.Should().Be(TestContentType); firstEntry.Event.ToStringUtf8().Should() .Be(JsonSerializer.Serialize(bulkPublishData[0], client.InnerClient.JsonSerializerOptions)); - firstEntry.Metadata.Should().BeEmpty(); + firstEntry.Metadata.Count.Should().Be(2); + firstEntry.Metadata.Keys.Contains("key1").Should().BeTrue(); + firstEntry.Metadata.Keys.Contains("key2").Should().BeTrue(); + firstEntry.Metadata["key1"].Should().Be("value1"); + firstEntry.Metadata["key2"].Should().Be("value2"); var secondEntry = envelope.Entries[1]; @@ -209,8 +221,12 @@ await daprClient.BulkPublishEventAsync(TestPubsubName, TestTopicName, bulkPublis secondEntry.ContentType.Should().Be(TestContentType); secondEntry.Event.ToStringUtf8().Should() .Be(JsonSerializer.Serialize(bulkPublishData[1], client.InnerClient.JsonSerializerOptions)); - secondEntry.Metadata.Should().BeEmpty(); - + secondEntry.Metadata.Count.Should().Be(2); + secondEntry.Metadata.Keys.Contains("key1").Should().BeTrue(); + secondEntry.Metadata.Keys.Contains("key2").Should().BeTrue(); + secondEntry.Metadata["key1"].Should().Be("value1"); + secondEntry.Metadata["key2"].Should().Be("value2"); + // Create Response & Respond var response = new Autogenerated.BulkPublishResponse {