0Pricing
Advanced Spring Boot 4: Event-Driven Architecture (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 دروس في المجموع.

بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.

What Triggers a Rebalance

A rebalance reassigns partitions among consumers in a group. It happens when a consumer joins, leaves, crashes, or its session times out.

During a rebalance, processing pauses across the group.

The Cost of Rebalancing

Frequent rebalances hurt throughput: partitions are revoked and reassigned, in-flight work may be reprocessed, and local caches are invalidated.

Advanced consumers actively minimize and react to rebalances.

Rebalance Listener Hooks

A ConsumerRebalanceListener gives you two callbacks:

  • onPartitionsRevoked — called before partitions are taken away.
  • onPartitionsAssigned — called after new partitions are granted.

Committing on Revoke

Use onPartitionsRevoked to commit offsets for work completed so far, avoiding duplicate processing after reassignment.

public void onPartitionsRevoked(Collection<TopicPartition> parts) {
    consumer.commitSync(currentOffsets);
}

Wiring It in Spring

In Spring Kafka, implement ConsumerAwareRebalanceListener and set it on the container properties.

factory.getContainerProperties()
    .setConsumerRebalanceListener(myRebalanceListener);

Static Membership

Static membership assigns each consumer a stable group.instance.id. On a brief restart, the broker keeps its partitions instead of triggering a rebalance.

spring:
  kafka:
    consumer:
      properties:
        group.instance.id: consumer-pod-1

Session and Heartbeat Timeouts

Static membership relies on session.timeout.ms. If a consumer rejoins within the session window using the same instance id, no rebalance occurs.

session.timeout.ms: 45000
heartbeat.interval.ms: 3000

Cooperative Rebalancing

The CooperativeStickyAssignor reassigns only the partitions that must move, instead of revoking everything (stop-the-world). This dramatically reduces rebalance impact.

partition.assignment.strategy: org.apache.kafka.clients.consumer.CooperativeStickyAssignor

Avoiding Poll Timeouts

If processing a batch exceeds max.poll.interval.ms, the broker assumes the consumer is dead and rebalances. Keep per-poll work bounded or raise the interval.

Combining Strategies

For resilient consumers, combine static membership (avoid restart churn), cooperative rebalancing (smaller moves), and a rebalance listener (clean offset commits).

Putting It Together

Rebalances are unavoidable but controllable. Listeners let you commit cleanly, static membership avoids needless rebalances on restart, and cooperative assignment limits disruption.

Quick Check

Test your understanding of rebalancing.

Recap

You learned advanced rebalance handling.

  • Rebalances pause processing and can reprocess work.
  • Rebalance listeners let you commit offsets on revoke.
  • Static membership avoids rebalances on brief restarts.
  • Cooperative assignment reduces stop-the-world disruption.

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

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

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

ماذا ستتعلم في «مستمعو إعادة التوازن والعضوية الثابتة»؟

تعلّم كيف تعطل إعادة موازنة مجموعة المستهلكين المعالجة، وكيف يقلل مستمعو إعادة التوازن والعضوية الثابتة من التوقف وفقدان الحالة. تتمرن على 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. إيقاف المستهلكين مؤقتًا واستئنافهم
  3. التزامن وإدارة مؤشرات الترابط
  4. مستمعو إعادة التوازن والعضوية الثابتة
← العودة إلى Advanced Spring Boot 4: Event-Driven Architecture (Kafka)