Skip to main content
PreparationZone Logo
PrepZone

Error Handlers, Retry, and DLT in Spring

DefaultErrorHandler, exponential backoff, and DeadLetterPublishingRecoverer for VaultCommerce consumers.

Pass checkpoint below

Why this matters

  • VaultCommerce inventory listener retries 3× with 2s backoff then DLT.
  • Classifier exceptions: AvroTypeException → not retryable, straight to DLT.
  • SeekToCurrentErrorHandler legacy — use DefaultErrorHandler in Spring Kafka 3.x.
  • Observability: metric tags on retry count and DLT publish.
OrderServiceVaultCommerce
vaultcommerce.orders.placed.v1
InventoryConsumer
KafkaTemplate publishes to a topic. @KafkaListener consumes from a consumer group.

Error handler setup

DefaultErrorHandler + DeadLetterPublishingRecoverer + FixedBackOff. Custom ConsumerRecordRecoverer for logging PII-scrubbed payloads. VaultCommerce registers handler on ConcurrentKafkaListenerContainerFactory bean.

Key points

  • DefaultErrorHandler — Spring Kafka 3 unified error handling
  • DeadLetterPublishingRecoverer — publishes failed record to DLT
  • FixedBackOff / ExponentialBackOff — delay between retries
  • @RetryableTopic — declarative retry topic generation
  • notRetryableExceptions — skip retry for deterministic failures

The rest of this guide is part of Pro

Free covers every fresher guide in full. Pro unlocks Senior, Staff and Architect guides across every track.

Still to come · 2 sections

  • RetryableTopic alternative
  • VaultCommerce rollout checklist

Test yourself

Answer these before moving on — recall is what makes it stick.