Retry Topicsによるノンブロッキング再試行
Spring Kafkaの@RetryableTopicを使い、時間を置いたノンブロッキング再試行を行います。コンシューマーの応答性を保ちながら、失敗したメッセージを再処理します。
「Retry Topicsによるノンブロッキング再試行」はCoddyKit上の無料Advanced Spring Boot 4: Event-Driven Architecture (Kafka)レッスンです。 これはレッスン4/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはAdvanced Spring Boot 4: Event-Driven Architecture (Kafka)学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 Advanced Spring Boot 4: Event-Driven Architecture (Kafka)コースには全4レッスンが含まれています。
このレッスンの一部はまだ翻訳されておらず、英語で表示されています。
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.
AI チューターと学ぶ Advanced Spring Boot 4: Event-Driven Architecture (Kafka) — 無料
ブラウザでリアルコードを書いて実行し、24/7 の AI チューターから瞬時にサポートを受け、ウェブまたはアプリで続きから学習できます。
- コース
- 12
- レッスン
- 48
よくある質問
「Retry Topicsによるノンブロッキング再試行」レッスンは無料ですか?
はい。「Retry Topicsによるノンブロッキング再試行」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、Advanced Spring Boot 4: Event-Driven Architecture (Kafka)コースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 Advanced Spring Boot 4: Event-Driven Architecture (Kafka)コースには全4レッスンが含まれています。
「Retry Topicsによるノンブロッキング再試行」で何を学びますか?
Spring Kafkaの@RetryableTopicを使い、時間を置いたノンブロッキング再試行を行います。コンシューマーの応答性を保ちながら、失敗したメッセージを再処理します。 ブラウザで直接実行するハンズオンコードでAdvanced Spring Boot 4: Event-Driven Architecture (Kafka)を演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。
Advanced Spring Boot 4: Event-Driven Architecture (Kafka)を始めるのに経験は必要ですか?
事前経験は必要ありません。CoddyKitのAdvanced Spring Boot 4: Event-Driven Architecture (Kafka)は初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン4/4です。
「Retry Topicsによるノンブロッキング再試行」レッスンにはどのくらい時間がかかりますか?
ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。
このAdvanced Spring Boot 4: Event-Driven Architecture (Kafka)レッスンでコードを書いて実行できますか?
はい。すべてのAdvanced Spring Boot 4: Event-Driven Architecture (Kafka)レッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。
このコースのすべてのレッスン
- コンシューマー例外の処理
- Spring Retryによるリトライ機構
- デッドレタートピック(DLT)の実装
- Retry Topicsによるノンブロッキング再試行