listener-pattern

Create session-based Service Bus listeners with dead-letter reprocessing for .NET microservices.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Provides a consistent, production-ready pattern for building Service Bus session-based listeners as hosted services so messages are processed in aggregate-ordered fashion and dead letters are handled reliably.

Core Features & Use Cases

  • Session-based ordering: Uses a ServiceBusSessionProcessor configured for strict per-session ordering and high parallelism across sessions.
  • DLQ pairing: Includes a paired dead-letter processor to reprocess messages from the dead letter queue with the same routing logic.
  • Typed handling and dispatch: Performs typed deserialization, subject-based routing to generic handlers, and MediatR dispatch within a scoped service provider while using explicit Complete/Abandon semantics and Serilog enrichment.
  • Use Case: Implement an OrdersListener that processes OrderCreated and OrderUpdated events per aggregate session, completes successful handlers, and reprocesses dead letters with conservative concurrency.

Quick Start

Create an IHostedService that constructs a ServiceBusSessionProcessor and a paired dead-letter ServiceBusProcessor, configure AutoCompleteMessages=false and PrefetchCount=1, implement subject-based routing to typed handlers, and register the listener as a hosted service.

Frequently Asked Questions about listener-pattern

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

FAQPage Schema
How do I process Service Bus messages in order with high throughput in a .NET microservice?

To process Service Bus messages in order with high throughput, use a session-based ServiceBusSessionProcessor hosted in IHostedService. This enables strict per-session ordering while maintaining high parallelism across sessions for aggregate-ordered message handling.

What is the best way to handle Service Bus dead-letter reprocessing in .NET?

The best way to handle dead-letter reprocessing is pairing your session processor with a dead-letter ServiceBusProcessor. This applies the same subject-based routing and typed deserialization to reprocess messages from the dead-letter queue with conservative concurrency.

Can I use MediatR to dispatch Service Bus messages within a scoped service provider?

Yes, you can dispatch Service Bus messages using MediatR within a scoped service provider. The pattern performs typed deserialization and subject-based routing to generic handlers before dispatching, ensuring correct dependency injection scoping per message.

Does a Service Bus session processor require explicit message completion to avoid reprocessing?

Yes, explicit completion is required when AutoCompleteMessages is set to false. The processor relies on explicit Complete or Abandon semantics after handler execution to safely control message lifecycle and prevent unintended reprocessing.

How do I configure Serilog enrichment for Service Bus listener logging in .NET?

To configure Serilog enrichment for Service Bus listener logging, integrate Serilog within your IHostedService implementation. The logging framework enriches message processing events alongside typed deserialization and MediatR dispatch for structured operational observability.