Designs .NET broker consumers, producers, background processing, idempotency, outbox/inbox, bounded retries, dead-lettering, and graceful shutdown. Use when message delivery semantics matter; do not use for in-process async queues only (use async-concurrency).
Installs into .claude/skills of the current project.
Sponsors
SSkills DirectorySkills Directory
Know which skills are safe — weekly.
SSkills DirectorySkills Directory
Is that skill safe to install?
Are you the author of Messaging Patterns?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/k4ndev-messaging-patterns)
---
name: messaging-patterns
description: Designs .NET broker consumers, producers, background processing, idempotency, outbox/inbox, bounded retries, dead-lettering, and graceful shutdown. Use when message delivery semantics matter; do not use for in-process async queues only (use async-concurrency).
---
# Messaging Patterns
## Purpose
Make asynchronous message processing reliable under redelivery, partial failure, deployment, and shutdown.
## Scope
Broker delivery/acknowledgment, message contracts, consumer concurrency, outbox/inbox, idempotency, retries, dead-letter handling, and hosted consumers.
## When to use
- A system uses RabbitMQ, Kafka, Azure Service Bus, MassTransit, Rebus, Wolverine, or another broker.
- User asks about duplicate delivery, dual writes, ordering, poison messages, or consumer recovery.
## Do not use for
- Process-local `Channel<T>`/task coordination without broker semantics: use `async-concurrency`.
- General background hosted service with no messaging: use `aspnetcore-patterns` or `async-concurrency`.
- Broker runtime incident collection: use `dotnet-diagnostics`.
## Required context
Identify broker/client versions, delivery guarantee and acknowledgment timing, transaction support, message identity/schema, side effects, concurrency/prefetch, retry/DLQ topology, deployment, and shutdown timeout.
## Workflow
1. Trace publish -> broker persistence -> delivery -> handler side effect -> acknowledgment; document crash windows.
2. Assume at-least-once delivery unless a precise broker configuration proves otherwise; design side effects idempotently by stable message/business identity.
3. For atomic database state + publication, use a transactional outbox and relay; consumers may use inbox/dedup within their DB transaction.
4. Separate transient from permanent failures; bound attempts/backoff and avoid retry storms. Route poison messages to monitored dead-letter storage with replay ownership.
5. Bound prefetch, consumer concurrency, payload size, and in-flight work; state ordering guarantees/partition key requirements.
6. Version message contracts additively; coordinate incompatible changes with producer/consumer rollout.
7. During shutdown stop accepting new deliveries, settle/finish in-flight work within host limits, and make redelivery safe.
8. Test duplicate delivery, crash-before-ack, transient/permanent failure, DLQ replay, contract evolution, and graceful stop.
## Decision rules
- Exactly-once broker delivery does not guarantee exactly-once business effects across external systems.
- Never hold a database transaction open while waiting on remote broker I/O unless the design explicitly requires and supports it.
- Use a process-local bounded channel only when durability across process loss is not required.
## Expected output format
Provide delivery timeline, crash-window analysis, idempotency/outbox strategy, retry/DLQ limits, ordering/concurrency assumptions, shutdown plan, and failure-injection tests.
## Common mistakes
- Acknowledging before durable effects, unbounded retries/prefetch, database-plus-broker dual write, or assuming a retry policy makes handlers idempotent.
## Edge cases
- Outbox relays can publish twice if they crash before marking sent; downstream idempotency remains necessary.
- Message TTL/retention and schema compatibility differ by broker; verify configured semantics.
- Cancellation during a committed side effect can trigger redelivery; use dedupe rather than treating cancellation as rollback.
## Examples
See [messaging examples](examples.md) for an outbox row and idempotent consumer transaction.
## Test scenarios
- Positive: “An order commits but RabbitMQ publish fails; design reliable delivery and duplicate-safe consumer.”
- Negative: “A local worker queue needs backpressure but no persistence” routes to `async-concurrency`.
- Boundary: “Diagnose consumer lag from runtime traces and counters” selects `dotnet-diagnostics`; broker delivery design remains this skill.
## Related skills
`async-concurrency`, `dotnet-diagnostics`, `logging-observability`, `efcore-patterns`, `testing-quality`.