0Pricing
Advanced Spring Boot 4: Event-Driven Architecture (Kafka) · درس

إعادات المحاولة غير الحاجبة باستخدام موضوعات إعادة المحاولة

تعلّم استخدام @RetryableTopic الخاص بـ Spring Kafka لتنفيذ إعادات محاولة غير حاجبة ومتأخرة زمنيًا، تُبقي المستهلك مستجيبًا أثناء إعادة معالجة الرسائل الفاشلة.

إعادات المحاولة غير الحاجبة باستخدام موضوعات إعادة المحاولة درس مجاني في Advanced Spring Boot 4: Event-Driven Architecture (Kafka) على CoddyKit. هذا هو الدرس 4 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في 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 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.

الأسئلة الشائعة

هل درس «إعادات المحاولة غير الحاجبة باستخدام موضوعات إعادة المحاولة» مجاني؟

نعم — نص درس «إعادات المحاولة غير الحاجبة باستخدام موضوعات إعادة المحاولة» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة Advanced Spring Boot 4: Event-Driven Architecture (Kafka)، انتقل إلى CoddyKit PRO. تتضمن دورة Advanced Spring Boot 4: Event-Driven Architecture (Kafka) 4 دروس في المجموع.

ماذا ستتعلم في «إعادات المحاولة غير الحاجبة باستخدام موضوعات إعادة المحاولة»؟

تعلّم استخدام @RetryableTopic الخاص بـ Spring Kafka لتنفيذ إعادات محاولة غير حاجبة ومتأخرة زمنيًا، تُبقي المستهلك مستجيبًا أثناء إعادة معالجة الرسائل الفاشلة. تتمرن على Advanced Spring Boot 4: Event-Driven Architecture (Kafka) مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.

هل أحتاج إلى خبرة سابقة لأبدأ Advanced Spring Boot 4: Event-Driven Architecture (Kafka)؟

لا تُشترط خبرة سابقة. Advanced Spring Boot 4: Event-Driven Architecture (Kafka) على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 4 من أصل 4.

كم من الوقت يستغرق درس «إعادات المحاولة غير الحاجبة باستخدام موضوعات إعادة المحاولة»؟

معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.

هل يمكنني كتابة وتشغيل أكواد في درس Advanced Spring Boot 4: Event-Driven Architecture (Kafka) هذا؟

نعم. كل درس في Advanced Spring Boot 4: Event-Driven Architecture (Kafka) يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.

جميع الدروس في هذه الدورة

  1. معالجة استثناءات المستهلكين
  2. آليات إعادة المحاولة باستخدام Spring Retry
  3. تنفيذ مواضيع الرسائل الميتة (DLT)
  4. إعادات المحاولة غير الحاجبة باستخدام موضوعات إعادة المحاولة
← العودة إلى Advanced Spring Boot 4: Event-Driven Architecture (Kafka)