Nieblokujące ponawianie prób z Retry Topics
Nauczą się Państwo używać @RetryableTopic z Spring Kafka do wykonywania nieblokujących, opóźnionych czasowo ponowień, które utrzymują responsywność konsumenta podczas ponownego przetwarzania nieudanych wiadomości.
Nieblokujące ponawianie prób z Retry Topics to bezpłatna lekcja Advanced Spring Boot 4: Event-Driven Architecture (Kafka) na CoddyKit. To lekcja 4 z 4. Możesz przeczytać całą lekcję poniżej za darmo — a potem ćwiczyć ją interaktywnie w przeglądarce z wbudowanym edytorem kodu i tutorem AI dostępnym 24/7. To część ścieżki edukacyjnej Advanced Spring Boot 4: Event-Driven Architecture (Kafka), a Twój postęp synchronizuje się między webem a aplikacją CoddyKit. Kurs Advanced Spring Boot 4: Event-Driven Architecture (Kafka) zawiera 4 lekcji w sumie.
Części tej lekcji nie zostały jeszcze przetłumaczone i są wyświetlane po angielsku.
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 originalTopicBlocking 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.
@RetryableTopiccreates retry topics automatically.- Configure attempts, backoff, and a multiplier.
- Filter retryable exceptions with include/exclude.
- Use
@DltHandlerfor permanently failed records.
Często zadawane pytania
Czy lekcja „Nieblokujące ponawianie prób z Retry Topics” jest bezpłatna?
Tak — pełny tekst „Nieblokujące ponawianie prób z Retry Topics” jest dostępny za darmo tutaj w sieci. Aby ćwiczyć ją interaktywnie (wbudowany edytor kodu i tutor AI dostępny 24/7) i odblokować resztę kursu Advanced Spring Boot 4: Event-Driven Architecture (Kafka), przejdź na CoddyKit PRO. Kurs Advanced Spring Boot 4: Event-Driven Architecture (Kafka) zawiera 4 lekcji w sumie.
Co nauczysz się w „Nieblokujące ponawianie prób z Retry Topics”?
Nauczą się Państwo używać @RetryableTopic z Spring Kafka do wykonywania nieblokujących, opóźnionych czasowo ponowień, które utrzymują responsywność konsumenta podczas ponownego przetwarzania nieudany… Ćwiczysz Advanced Spring Boot 4: Event-Driven Architecture (Kafka) z praktycznym kodem, który uruchamiasz bezpośrednio w przeglądarce, a tutor AI dostępny 24/7 odpowiada na Twoje pytania podczas pracy nad lekcją.
Czy potrzebuję doświadczenia, aby zacząć Advanced Spring Boot 4: Event-Driven Architecture (Kafka)?
Nie wymagamy żadnego doświadczenia. Advanced Spring Boot 4: Event-Driven Architecture (Kafka) w CoddyKit jest strukturyzowany dla początkujących i zaawansowanych użytkowników, więc możesz zacząć tutaj lub od początku i uczyć się w swoim tempie. To lekcja 4 z 4.
Ile czasu zajmuje lekcja „Nieblokujące ponawianie prób z Retry Topics”?
Większość lekcji CoddyKit trwa około 5–10 minut. Każda lekcja to mały, interaktywny krok, dzięki czemu robisz systematyczne postępy i zawsze wracasz dokładnie do tego samego miejsca — na webie i w aplikacji.
Czy mogę pisać i uruchamiać kod w tej lekcji Advanced Spring Boot 4: Event-Driven Architecture (Kafka)?
Tak. Każda lekcja Advanced Spring Boot 4: Event-Driven Architecture (Kafka) zawiera wbudowany edytor kodu, więc piszesz i uruchamiasz prawdziwy kod bezpośrednio w przeglądarce i od razu otrzymujesz sprzężenie zwrotne od AI — bez konfiguracji na komputerze.
Wszystkie lekcje w tym kursie
- Obsługa wyjątków konsumenta
- Mechanizmy ponawiania z Spring Retry
- Implementowanie tematów dead letter (DLT)
- Nieblokujące ponawianie prób z Retry Topics