Idempotency for Subscribers
Overview
Why Do Messages Get Redelivered?
Scenario
Description
What Problems Can Duplicate Processing Cause?
Quick Start
Step 1: Add Configuration to appsettings.json
Step 2: Register Idempotency Services
Configuration Options
FlexIdempotency Section
Setting
Default
Description
FlexCache Section (for Cache Store)
Setting
Default
Description
Store Types
Option 1: Cache Store (Default)
Backend
Use Case
Setup Complexity
Option 2: Database Store (EF Core)
Cache Store Configuration
Development: In-Memory Only
Production: Redis Backend
Step 1: Install NuGet Package
Step 2: Configure Redis
Step 3: Add Connection String
Production: SQL Server Distributed Cache
Step 1: Install NuGet Package
Step 2: Create the Cache Table
Step 3: Configure SQL Server Distributed Cache
Step 4: Add Connection String
Database Store Configuration (EF Core)
Step 1: Configure Store Type
Step 2: Choose Your DbContext Approach
Approach
Description
Best For
Option A: Dedicated Context (Recommended for Isolation)
Option B: Shared Context (Simpler Setup)
Which Approach Should I Choose?
Consideration
Dedicated Context
Shared Context
Database Table Structure
Column
Type
Description
Cleanup of Expired Records
Opting Out of Idempotency
How It Works
What Happens When a Message Arrives
Why Your Code Doesn't Need to Change
Key Points
Troubleshooting
Events Being Skipped Unexpectedly
Duplicate Processing Still Occurring
Debug Logging
Best Practices
1. Choose the Right Store Type
Scenario
Recommended Store
2. Set Appropriate TTL
3. Monitor Storage Growth
4. Use SkipIdempotency Sparingly
Complete Example
appsettings.json
IdempotencyConfig.cs
CommonHostConfig.cs
Summary
Feature
Description
Last updated