Skip to content

Commit 7fc9130

Browse files
committed
chor: Update readme with Service Bus Batch publish description and example
1 parent b003eea commit 7fc9130

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,27 @@ internal class BarPublisher
115115
}
116116
```
117117

118+
### Batch Publish
119+
120+
Multiple messages can also be published in batches to a topic or queue. Simply call the `PublishAsync` method with a list of messages. The messages will be added to a batch until the batch is full before it the batch is published and continue to work on the remaining messages. This process continues until all messages are consumed.
121+
122+
An `InvalidOperationException` is thrown if a single message cannot fit inside a batch by itself. In this case, any previous published batches will not be rolled back and any remaining messages will remain unpublished.
123+
124+
```csharp
125+
internal class BarBatchPublisher
126+
{
127+
private readonly IServiceBusPublisher publisher;
128+
129+
public BarBatchPublisher(IServiceBusPublisher publisher)
130+
{
131+
this.publisher = publisher;
132+
}
133+
134+
public Task Publish(object[] messages)
135+
=> publisher.PublishAsync("[existing servicebus topic]", messages);
136+
}
137+
```
138+
118139
Here's a full example of how to use the publishers above using a Minimal API setup (SwaggerUI enabled) with a single endpoint called `POST /data` that accepts a simple request body `{ "a": "string", "b": "string", "c": "string" }` which publishes the request to an EventHub and a ServiceBus topic
119140

120141
```csharp

0 commit comments

Comments
 (0)