batch-processing

Implement session-aware batch event processing for Service Bus queues with controlled concurrency.

4|1|Updated Mar 15, 2026
One-click install
npx skills add https://github.com/FaysilAlshareef/dotnet-ai-kit --skill batch-processing-faysilalshareef
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: batch-processing
Source: https://github.com/FaysilAlshareef/dotnet-ai-kit/tree/main/skills/microservice/processor/batch-processing
Command: npx skills add https://github.com/FaysilAlshareef/dotnet-ai-kit --skill batch-processing-faysilalshareef

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Implements reliable, session-aware batch processing for Service Bus queues so microservices can aggregate and process related messages without overwhelming resources or duplicating work. It replaces inappropriate use of ServiceBusSessionProcessor for batching with a controlled BackgroundService pattern to ensure predictable concurrency and failure handling.

Core Features & Use Cases

  • BackgroundService batch listener that accepts sessions one at a time and processes messages in groups.
  • Concurrency control via SemaphoreSlim to limit simultaneous session processing.
  • Manual session acceptance using AcceptNextSessionAsync and batch retrieval with ReceiveMessagesAsync.
  • Deduplication by grouping messages on SourceId and keeping the first occurrence before creating a batch request.
  • Batch dispatch to IMediator as a single BatchItemChanged request and coordinated complete/abandon semantics.
  • Paired DLQ handler that processes dead-lettered messages individually and robust error/abandon strategies.

Quick Start

Use the batch-processing skill to implement a BackgroundService that accepts sessions with AcceptNextSessionAsync, batches messages via ReceiveMessagesAsync, deduplicates by SourceId, and sends a BatchItemChanged to IMediator while completing or abandoning messages based on processing outcome.

Frequently Asked Questions about batch-processing

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I batch process Service Bus sessions without duplicating work in .NET?

Batch processing Service Bus sessions without duplicating work requires a BackgroundService that uses AcceptNextSessionAsync to manually accept sessions, groups messages via ReceiveMessagesAsync, and deduplicates by SourceId before dispatching a single batch request. This pattern prevents resource exhaustion and ensures predictable failure handling.

Why should I use a BackgroundService instead of ServiceBusSessionProcessor for batch processing?

Using a BackgroundService instead of ServiceBusSessionProcessor for batch processing provides controlled concurrency via SemaphoreSlim. This manual session acceptance approach replaces inappropriate processor usage by ensuring predictable simultaneous session limits, proper batch retrieval, and coordinated complete or abandon semantics for failure handling.

How do I handle dead-lettered messages when aggregating Service Bus sessions?

Handling dead-lettered messages when aggregating Service Bus sessions requires a paired DLQ handler that processes dead-lettered messages individually. This robust error strategy works alongside the main batch dispatch, applying proper complete and abandon semantics based on the specific processing outcome of each message.

Can I use MediatR to dispatch aggregated Service Bus messages in a microservice?

Yes, you can use MediatR to dispatch aggregated Service Bus messages by sending a single BatchItemChanged request. After the BackgroundService batches messages and deduplicates them by SourceId, it forwards the aggregated request to IMediator, completing or abandoning the original messages based on the dispatch outcome.

How do I limit concurrency when accepting Service Bus sessions manually?

Limiting concurrency when accepting Service Bus sessions manually requires a SemaphoreSlim to restrict simultaneous session processing. By wrapping the AcceptNextSessionAsync and ReceiveMessagesAsync calls with the semaphore, the BackgroundService ensures that the microservice aggregates related messages without overwhelming system resources.