Skip to content

Commit 8921ef2

Browse files
benperkggailey777
andauthored
Update articles/azure-functions/functions-dotnet-class-library.md
Co-authored-by: Glenn Gailey <[email protected]>
1 parent 2caea4d commit 8921ef2

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

articles/azure-functions/functions-dotnet-class-library.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -336,12 +336,14 @@ namespace ServiceBusCancellationToken
336336
}
337337
```
338338
A common pattern for iterating through an array uses the foreach statement. Within the foreach statement, prior to processing the message, check if a cancellation token has been generated. The most common scenario will be that the IsCancellationRequested property is false and, in that case, your coded business logic will execute. In a seldom, but realistic scenario that IsCancellationRequested is true, you will need to take some precautionary actions. For example, writing a log which stores the fact that this happened and perhaps store the portion of the message batch which has not yet been processed. If you do the latter, then your startup code needs to check if there are any message batches which experienced this shutdown procedure. The actual requirement is based on your specific scenario.
339-
Consider that processing messages in batches is possible with an Event Hub triggered function. Notice that the events parameter is declared as an array like the following, ```EventData[] events```.
339+
Event Hubs is an other trigger that supports batch processing messages. The following example is a function method definition for an Event Hubs trigger with a cancellation token that accepts an incoming batch as an array of [EventData](/dotnet/api/microsoft.azure.eventhubs.eventdata) objects:
340+
340341
```csharp
341342
public async Task Run([EventHubTrigger("csharpguitar", Connection = "EH_CONN")]
342343
EventData[] events, CancellationToken cancellationToken, ILogger log)
343344
```
344-
The pattern to process a batch of events is the same as the one shown for processing a batch of Service Bus messages. In each case you should check for a cancellation token prior to the processing of each item in the array, and if present, manage it as per your business requirements.
345+
346+
The pattern to process a batch of Event Hubs events is similar to the previous example of processing a batch of Service Bus messages. In each case, you should check the cancellation token for a cancellation state before processing each item in the array. When a pending shutdown is detected in the middle of the batch, handle it gracefully based on your business requirements.
345347

346348
## Logging
347349

0 commit comments

Comments
 (0)