Advanced Spring Boot 4: Event-Driven Architecture (Kafka) · Lección

Reintentos no bloqueantes con Retry Topics

Aprenda a usar @RetryableTopic de Spring Kafka para realizar reintentos no bloqueantes y retrasados, manteniendo receptivo el consumidor mientras reprocesa los mensajes fallidos.

Lección 4 de 413 pasos

Reintentos no bloqueantes con Retry Topics es una lección gratuita de Advanced Spring Boot 4: Event-Driven Architecture (Kafka) en CoddyKit. Esta es la lección 4 de 4. Puedes leer la lección completa abajo gratuitamente — luego la practicas en el navegador con un editor de código integrado y un tutor de IA 24/7. Forma parte de la ruta de aprendizaje de Advanced Spring Boot 4: Event-Driven Architecture (Kafka), y tu progreso se sincroniza en la web y la app de CoddyKit. El curso de Advanced Spring Boot 4: Event-Driven Architecture (Kafka) incluye 4 lecciones en total.

Partes de esta lección aún no han sido traducidas y se muestran en inglés.

The Problem with Blocking Retries

Blocking retries (Spring Retry) pause the consumer thread between attempts. A long backoff blocks the partition, stalling all later records.

Non-blocking retries solve this by moving failed records to dedicated retry topics.

How Retry Topics Work

When processing fails, the record is forwarded to a retry topic with a delay. A separate listener consumes the retry topic after the delay and tries again.

  • The main consumer keeps moving forward.
  • Each retry level can have a longer delay.

Enabling RetryableTopic

Annotate your listener with @RetryableTopic. Spring auto-creates the retry and DLT topics.

@RetryableTopic
@KafkaListener(topics = "orders")
public void handle(Order order) {
    paymentService.charge(order);
}

Configuring Attempts and Backoff

Customize the number of attempts and the delay strategy directly in the annotation.

@RetryableTopic(
    attempts = "4",
    backoff = @Backoff(delay = 1000, multiplier = 2.0))
@KafkaListener(topics = "orders")
public void handle(Order order) { /* ... */ }

Generated Topic Names

By default Spring creates topics like orders-retry-0, orders-retry-1, and finally orders-dlt.

Each retry topic corresponds to one backoff level.

Exponential vs Fixed Backoff

Set multiplier for exponential growth, or omit it for fixed delays.

  • Fixed: 1s, 1s, 1s.
  • Exponential: 1s, 2s, 4s.

Exponential is better for transient downstream outages.

Selecting Retryable Exceptions

Only retry exceptions that are transient. Use include or exclude to control which exceptions trigger retries.

@RetryableTopic(
    include = { RemoteServiceException.class },
    exclude = { ValidationException.class })
@KafkaListener(topics = "orders")
public void handle(Order order) { /* ... */ }

Handling the DLT

After all attempts fail, the record lands on the DLT. Add a @DltHandler method to react.

@DltHandler
public void handleDlt(Order order) {
    log.error("Order permanently failed: {}", order.getId());
}

Reading Retry Headers

Retry records carry headers such as the attempt count and original timestamp, letting you log how far a message progressed.

@Header(KafkaHeaders.ORIGINAL_TOPIC) String originalTopic

Blocking vs Non-Blocking

Use blocking retries for very short, immediate transients; use non-blocking retry topics when delays are longer and partition throughput matters.

Putting It Together

Non-blocking retries keep consumers responsive while still giving failed messages multiple chances. Combine @RetryableTopic, exponential backoff, exception filtering, and a @DltHandler.

Quick Check

Test your understanding of retry topics.

Recap

You learned non-blocking retries.

  • @RetryableTopic creates retry topics automatically.
  • Configure attempts, backoff, and a multiplier.
  • Filter retryable exceptions with include/exclude.
  • Use @DltHandler for permanently failed records.
Gratis para empezar

Aprende Advanced Spring Boot 4: Event-Driven Architecture (Kafka) con un tutor de IA — gratis

Escribe y ejecuta código real en tu navegador, obtén ayuda instantánea de un tutor de IA disponible 24/7 y continúa donde lo dejaste en la web o en la aplicación.

Cursos
12
Lecciones
48

Preguntas frecuentes

¿La lección «Reintentos no bloqueantes con Retry Topics» es gratis?

Sí — el texto completo de «Reintentos no bloqueantes con Retry Topics» es gratis para leer aquí en la web. Para practicarla de forma interactiva (editor de código integrado y tutor de IA 24/7) y desbloquear el resto del curso de Advanced Spring Boot 4: Event-Driven Architecture (Kafka), actualiza a CoddyKit PRO. El curso de Advanced Spring Boot 4: Event-Driven Architecture (Kafka) incluye 4 lecciones en total.

¿Qué aprenderé en «Reintentos no bloqueantes con Retry Topics»?

Aprenda a usar @RetryableTopic de Spring Kafka para realizar reintentos no bloqueantes y retrasados, manteniendo receptivo el consumidor mientras reprocesa los mensajes fallidos. Practicas Advanced Spring Boot 4: Event-Driven Architecture (Kafka) con código real que ejecutas directamente en el navegador, y un tutor de IA 24/7 responde tus preguntas mientras trabajas en la lección.

¿Necesito experiencia previa para empezar Advanced Spring Boot 4: Event-Driven Architecture (Kafka)?

No se requiere experiencia previa. Advanced Spring Boot 4: Event-Driven Architecture (Kafka) en CoddyKit está estructurado para principiantes hasta estudiantes avanzados, así que puedes empezar aquí o desde el inicio y avanzar a tu ritmo. Esta es la lección 4 de 4.

¿Cuánto tiempo toma la lección «Reintentos no bloqueantes con Retry Topics»?

La mayoría de las lecciones de CoddyKit toman alrededor de 5–10 minutos. Cada una es compacta e interactiva, así que avanzas constantemente y retomas exactamente por donde dejaste en la web y la app.

¿Puedo escribir y ejecutar código en esta lección de Advanced Spring Boot 4: Event-Driven Architecture (Kafka)?

Sí. Cada lección de Advanced Spring Boot 4: Event-Driven Architecture (Kafka) incluye un editor de código integrado, así que escribes y ejecutas código real directamente en tu navegador y obtienes retroalimentación instantánea de IA — sin configuración local necesaria.

Todas las lecciones de este curso

  1. Gestión de excepciones de consumidores
  2. Mecanismos de reintento con Spring Retry
  3. Implementación de Dead Letter Topics (DLT)
  4. Reintentos no bloqueantes con Retry Topics
← Volver a Advanced Spring Boot 4: Event-Driven Architecture (Kafka)