Skip to content

Commit

Permalink
attach metadata to each individual message in bulkpublish if it exists
Browse files Browse the repository at this point in the history
Signed-off-by: Chris Walsh <[email protected]>
  • Loading branch information
cwalsh2189 committed Jan 6, 2025
1 parent 8b9f932 commit a371edd
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
6 changes: 6 additions & 0 deletions src/Dapr.Client/DaprClientGrpc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<TValue>(
entry.EntryId, events[counter], entry.ContentType, entry.Metadata));
Expand Down
28 changes: 22 additions & 6 deletions test/Dapr.Client.Test/BulkPublishEventApiTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,16 +106,24 @@ 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];

secondEntry.EntryId.Should().Be("1");
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
{
Expand Down Expand Up @@ -201,16 +209,24 @@ 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];

secondEntry.EntryId.Should().Be("1");
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
{
Expand Down

0 comments on commit a371edd

Please sign in to comment.