0008: Park messages that can't be handled yet, and redeliver them from Postgres
Status: Accepted ยท Date: 2026-10-13
Contextโ
Messages from PVC Connect arrive in any order. A CreditMemoIssued can overtake its WorkOrderInvoiceFinalized; a
credit for an invoice that is still PendingTax (AvaTax outage) can't be applied yet; two writers can race. Sending
those to _error turns every AvaTax outage into manual queue replays. RabbitMQ has no built-in delayed delivery, and
the delayed-message exchange plugin does not load on RabbitMQ 4.3.
Decisionโ
A consume filter (DeferOnRetryLaterFilter) is the outermost step of every consumer endpoint:
- When the consumer fails with a retry-later error (
RetryLaterPolicy:original_not_received,original_not_committed,concurrent_update,provider_unavailable, and row-version, unique or serialization conflicts), the message is written todeferred_messagesin its own transaction and acknowledged. ItsFault<T>is held back, so senders don't see a failure. - The
deferred-message-redeliveryjob sends due rows back to their queue through the transactional outbox (send and row delete commit together), with anIntegrations-Redeliveryattempt header. - Waits: 1 m, 5 m, 15 m, 1 h, 4 h (
Messaging__RetryLaterDelays). After the last, the message goes to<queue>_errorwith itsFault<T>, as before.
Everything else: invalid messages (MessageValidationFilter) and business rejections go straight to _error;
unexpected transient exceptions get 5 immediate retries.
Consequencesโ
- Works the same on every transport (RabbitMQ, in-memory tests, Azure Service Bus later) and survives restarts.
- Parked messages are visible in
deferred_messages(runbook query), counted byintegrations.messages.deferred. - Redelivered messages get a new message id, so the inbox treats them as new deliveries; consumers are idempotent on the caller's ids anyway.
- Ordering of same-key messages is not guaranteed;
CustomerUpserted/VendorUpsertedcarry an optionalversionso stale changes are dropped.