انتقل إلى المحتوى
أمين أبوزيد
MID-028

Apache Kafka

  • 9 درس
  • 4 ساعة تدريب (تقدير)
في هذه الصفحة 8 موضوعات

نص الدروس والتمارين باللغة الإنجليزية، بينما تبقى واجهة الموقع وعناوين الدروس بالعربية.

نظرة عامة

الموضوعات

  • الوسطاء (Brokers)
  • المواضيع (Topics)
  • الأقسام (Partitions)
  • مجموعات المستهلكين (Consumer Groups)
  • الإزاحات (Offsets)
  • الترتيب

تعلّم أولًا

4 ساعة تدريب (تقدير)

مخرجات التعلم

  1. Explain brokers, topics, partitions, replicas, and the log model.
  2. Choose partition keys to preserve the ordering that matters.
  3. Explain consumer groups, offsets, commits, and rebalancing.
  4. Produce and consume with Spring for Apache Kafka, with error handling and a DLT.
  5. Configure producer durability (acks, idempotent producer).

الدروس

  1. 01Kafka كسجلّ موزّع
  2. 02المواضيع والأقسام والنسخ المتماثلة
  3. 03المفاتيح والترتيب
  4. 04مجموعات المستهلكين والإزاحات
  5. 05Spring for Apache Kafka
  6. 06معالجة الأخطاء ومواضيع الرسائل الميتة
  7. 07إعدادات متانة المنتِج
  8. 08عرض عملي: أحداث الطلبات من البداية إلى النهاية
  9. 09عرض عملي: ماذا تفعل إعادة الموازنة (rebalance) بالرسائل قيد المعالجة

المختبر والتمارين

Lab

MID-028-LAB1 · Order events on Kafka

Outcomes: 1–5 · Time: ~4 h

  1. Create orders (3 partitions). orders publishes OrderPlaced keyed by order ID with acks=all and idempotence enabled.
  2. inventory and payments consume in separate groups with a DefaultErrorHandler, back-off, and a DLT.
  3. Make handlers idempotent by eventId.
  4. Test: events of one order stay in order; restart a consumer mid-stream and confirm nothing is lost; send a poison record and find it in the DLT.

Acceptance: per-order ordering preserved; consumer restart loses nothing.

Exercises (assessment: partitioning and ordering scenarios; six exercises)

IDOutcomeTask
MID-028-EX011Draw a topic with 4 partitions and replication factor 3 over 3 brokers; mark leaders and followers.
MID-028-EX022Pick a key for: order events, per-customer notifications, sensor readings per device. Say what ordering you get.
MID-028-EX033A group has 3 consumers and a topic has 2 partitions. Describe the assignment and what happens when one consumer leaves.
MID-028-EX043Explain the failure when offsets are committed before processing and the failure when committed after.
MID-028-EX054Configure a Spring Kafka error handler that retries 3 times, 1 s apart, then publishes to a DLT.
MID-028-EX065Choose acks, min.insync.replicas, and idempotence for payment events and explain the trade-off.
أظهر الحلول
  • EX01 Each partition has one leader and two followers on different brokers; leaders spread across brokers.
  • EX02 Order events: orderId (per-order order). Notifications: customerId. Sensors: deviceId. No ordering across keys.
  • EX03 Two consumers get one partition each; one idles. If an active one leaves, rebalance gives its partition to the idle one.
  • EX04 Commit before: crash loses the record. Commit after: crash causes redelivery, so handlers must be idempotent.
  • EX05 new DefaultErrorHandler(new DeadLetterPublishingRecoverer(template), new FixedBackOff(1000L, 3)).
  • EX06 acks=all, replication factor 3, min.insync.replicas=2, enable.idempotence=true; cost is extra latency and reduced availability if two replicas are down.

الاختبار

Outcomes: O1 log model · O2 keys and ordering · O3 groups and offsets · O4 Spring and error handling · O5 producer durability.

اختبار ذاتي لك: لا توجد درجات، ولا يُحفظ أو يُرسل أي شيء. اختر إجابة ثم تحقق منها، ويمكنك المحاولة مرة أخرى كما تشاء.

  1. 1In Kafka, a consumed record is:O1
  2. 2Ordering is guaranteed:O1
  3. 3To keep all events of an order in order, key by:O2
  4. 4A null key means:O2
  5. 5Two groups subscribe to one topic. Each group gets:O3
  6. 6Within one group, a partition is read by:O3
  7. 7Committing offsets before processing risks:O3
  8. 8After retries are exhausted, a failed record is typically sent to:O4
  9. 9acks=all makes the leader wait for:O5
  10. 10The idempotent producer helps prevent:O5

الجزء العملي

Six exercises MID-028-EX01 to EX06 plus the lab. Pass: at least five exercises correct, per-order ordering demonstrated, no loss on consumer restart, and a poison record found in the DLT.

أخطاء شائعة

Random keys where order matters; auto-commit before processing; one partition for everything.

التقييم

Partitioning and ordering scenarios.

الصلة بالمسار الوظيفي

Large-scale messaging (SRB-006).

اكتب للبحث في المستويات والمراحل والوحدات والدروس.