Skip to main content

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:

  1. 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 to deferred_messages in its own transaction and acknowledged. Its Fault<T> is held back, so senders don't see a failure.
  2. The deferred-message-redelivery job sends due rows back to their queue through the transactional outbox (send and row delete commit together), with an Integrations-Redelivery attempt header.
  3. Waits: 1 m, 5 m, 15 m, 1 h, 4 h (Messaging__RetryLaterDelays). After the last, the message goes to <queue>_error with its Fault<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 by integrations.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/VendorUpserted carry an optional version so stale changes are dropped.