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.
0 commit comments