You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+21Lines changed: 21 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -115,6 +115,27 @@ internal class BarPublisher
115
115
}
116
116
```
117
117
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.
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
Copy file name to clipboardExpand all lines: src/Atc.Azure.Messaging/ServiceBus/IServiceBusPublisher.cs
+19-1Lines changed: 19 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -23,6 +23,24 @@ Task PublishAsync(
23
23
TimeSpan?timeToLive=null,
24
24
CancellationTokencancellationToken=default);
25
25
26
+
/// <summary>
27
+
/// Publishes multiple messages in batches. The list of messages will be split in multiple batches if the messages exceeds a single batch size.
28
+
/// </summary>
29
+
/// <param name="topicOrQueue">The topic or queue name.</param>
30
+
/// <param name="messages">The messages to be published.</param>
31
+
/// <param name="sessionId">Optional id for appending the message to a known session. If not set, then defaults to a new session.</param>
32
+
/// <param name="properties">Optional custom metadata about the message.</param>
33
+
/// <param name="timeToLive">Optional <see cref="TimeSpan"/> for message to be consumed. If not set, then defaults to the value specified on queue or topic.</param>
0 commit comments