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

اكتشاف الخدمات (Service Discovery)

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

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

نظرة عامة

الموضوعات

  • الاكتشاف المبني على DNS
  • الاكتشاف الأصلي للمنصة
  • موازنة الحِمل

تعلّم أولًا

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

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

  1. Explain client-side vs server-side discovery and load balancing.
  2. Use DNS-based discovery (Docker Compose now, Kubernetes Services in MID-057).
  3. Explain health-check-driven routing and what happens to in-flight requests during deployment.

الدروس

  1. 01العثور على الخدمات
  2. 02الاكتشاف المبني على DNS
  3. 03الاكتشاف الأصلي للمنصة
  4. 04استراتيجيات موازنة الحِمل
  5. 05عرض عملي: توسيع خدمة المخزون إلى ثلاث نسخ

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

Lab

MID-036-LAB1 · Scale out

Outcomes: 1–3 · Time: ~1.5 h Run three inventory replicas behind Compose DNS (no fixed host ports). Make orders call inventory by name and log which replica answered. Run a load test and kill one replica partway through. Record error counts and latency before, during, and after.

Acceptance: errors are limited to in-flight requests on the killed replica; a short written explanation says why, and what retries and graceful shutdown would change.

Exercises (assessment: quiz)

IDOutcomeTask
MID-036-EX011Compare client-side and server-side discovery in a table with an example of each.
MID-036-EX022Replace hard-coded hosts in the Shop config with Compose service names and environment variables.
MID-036-EX032Show that DNS resolves inventory to several addresses inside the Compose network and explain JVM caching effects.
MID-036-EX043Explain what a readiness probe does for routing during a rolling deployment.
MID-036-EX051Choose a load-balancing strategy for fast uniform GETs and for mixed fast and slow requests.
MID-036-EX063List steps for a graceful shutdown of a Spring Boot service so in-flight requests finish.
أظهر الحلول
  • EX01 Client-side: caller asks a registry and picks (Eureka). Server-side: caller uses a stable name or proxy that picks (Compose DNS, Kubernetes Service). Client-side adds library and registry; server-side hides it.
  • EX02 INVENTORY_URL: http://inventory:8080 in Compose and @Value("${inventory.url}") or a property class.
  • EX03 From the orders container, getent hosts inventory (or nslookup) lists addresses; JVM and HTTP client caches plus keep-alive connections can pin traffic to one replica.
  • EX04 Only instances reporting ready receive traffic; new Pods join after passing readiness and old ones leave before termination, so traffic does not hit instances that are starting or stopping.
  • EX05 Round robin for uniform GETs; least connections (or power of two choices) for mixed durations.
  • EX06 Enable server.shutdown=graceful, set a shutdown timeout, fail readiness first, wait for load balancer to stop sending traffic, then finish in-flight work and exit (verify property names for your Spring Boot version).

Outcome 3 is also covered by quiz Q08 to Q10.

الاختبار

Outcomes: O1 discovery and balancing styles · O2 DNS-based discovery · O3 health-driven routing and deployments.

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

  1. 1In client-side discovery, who picks the instance?O1
  2. 2Which is server-side discovery?O1
  3. 3Least-connections balancing suits:O1
  4. 4In Docker Compose, services reach each other by:O2
  5. 5Why can balancing look uneven with keep-alive connections?O2
  6. 6A hard-coded replica IP:O2
  7. 7A readiness probe decides:O3
  8. 8When a replica is killed during load, errors are mostly:O3
  9. 9Graceful shutdown helps by:O3
  10. 10On a platform that already provides discovery, adding a registry is:O3

الجزء العملي

Six exercises MID-036-EX01 to EX06 plus MID-036-LAB1. Pass: at least five exercises, 8 of 10 quiz answers, and a lab run with errors limited to in-flight requests and a correct explanation.

أخطاء شائعة

Hard-coded hosts; service registries added where the platform already provides discovery.

التقييم

Quiz.

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

Kubernetes Services (MID-057) and service mesh (SRB-009).

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