النشر والاشتراك باستخدام تبادلات Fanout
تعلّموا كيفية بث الرسائل إلى مستهلكين متعددين في آن واحد باستخدام نمط النشر والاشتراك في RabbitMQ، المبني على تبادلات Fanout والطوابير المؤقتة.
النشر والاشتراك باستخدام تبادلات Fanout درس مجاني في RabbitMQ Messaging & Async Systems على CoddyKit. هذا هو الدرس 4 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في RabbitMQ Messaging & Async Systems، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة RabbitMQ Messaging & Async Systems 4 دروس في المجموع.
بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.
Beyond a Single Consumer
Work queues deliver each message to one worker. But sometimes every interested consumer needs the same message — like broadcasting a live score to all dashboards.
This is the publish/subscribe pattern.
The Fanout Exchange
Pub/sub in RabbitMQ uses a fanout exchange, which copies every incoming message to all queues bound to it, ignoring routing keys entirely.
Declaring a Fanout Exchange
A producer declares the fanout exchange and publishes to it.
channel.exchangeDeclare('scores', 'fanout');
channel.basicPublish('scores', '', null, body);Empty Routing Key
Notice the routing key is an empty string. Fanout exchanges ignore it, so producers do not need to specify any routing logic at all.
Temporary Queues
Each subscriber usually wants a fresh, private queue. Declaring a queue with no name lets RabbitMQ generate a random one, and marking it exclusive auto-deletes it when the consumer disconnects.
String q = channel.queueDeclare().getQueue();Binding the Queue
The subscriber binds its temporary queue to the fanout exchange so it begins receiving broadcasts.
channel.queueBind(q, 'scores', '');Multiple Independent Subscribers
Because each subscriber has its own queue, they all get independent copies of every message. Adding a new subscriber does not affect the others.
Pub/Sub vs Work Queues
Key difference:
- Work queue — one queue, many workers, each message handled once
- Pub/sub — many queues, each subscriber gets every message
Common Use Cases
Fanout pub/sub fits:
- Live notifications and dashboards
- Cache invalidation across many nodes
- Broadcasting configuration changes
- Logging to multiple sinks
Messages Without Consumers
If no queue is bound to a fanout exchange when a message arrives, the message is simply discarded. Fanout does not store anything itself — queues do.
Scaling Subscribers
To scale pub/sub, just add more subscribers, each with its own temporary queue bound to the exchange. The fanout exchange handles fan-out automatically.
Quick Check
Test your pub/sub knowledge.
Recap
You learned the publish/subscribe pattern:
- Fanout exchanges broadcast to all bound queues
- The routing key is ignored
- Subscribers use temporary exclusive queues
- Each subscriber gets an independent copy of every message
This pattern is the foundation for notifications, cache invalidation, and live updates.
تعلم RabbitMQ Messaging & Async Systems مع معلم ذكاء اصطناعي — مجانًا
اكتب وقم بتشغيل أكوادك الفعلية في المتصفح، واحصل على مساعدة فورية من معلم ذكاء اصطناعي متاح 24/7، واستمر من حيث توقفت على الويب أو في التطبيق.
- الدورات
- 11
- الدروس
- 44
الأسئلة الشائعة
هل درس «النشر والاشتراك باستخدام تبادلات Fanout» مجاني؟
نعم — نص درس «النشر والاشتراك باستخدام تبادلات Fanout» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة RabbitMQ Messaging & Async Systems، انتقل إلى CoddyKit PRO. تتضمن دورة RabbitMQ Messaging & Async Systems 4 دروس في المجموع.
ماذا ستتعلم في «النشر والاشتراك باستخدام تبادلات Fanout»؟
تعلّموا كيفية بث الرسائل إلى مستهلكين متعددين في آن واحد باستخدام نمط النشر والاشتراك في RabbitMQ، المبني على تبادلات Fanout والطوابير المؤقتة. تتمرن على RabbitMQ Messaging & Async Systems مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.
هل أحتاج إلى خبرة سابقة لأبدأ RabbitMQ Messaging & Async Systems؟
لا تُشترط خبرة سابقة. RabbitMQ Messaging & Async Systems على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 4 من أصل 4.
كم من الوقت يستغرق درس «النشر والاشتراك باستخدام تبادلات Fanout»؟
معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.
هل يمكنني كتابة وتشغيل أكواد في درس RabbitMQ Messaging & Async Systems هذا؟
نعم. كل درس في RabbitMQ Messaging & Async Systems يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.
جميع الدروس في هذه الدورة
- مرحبًا بالعالم: قائمة انتظار بسيطة
- قوائم انتظار العمل: التوزيع العادل
- إقرارات استلام الرسائل واستمراريتها
- النشر والاشتراك باستخدام تبادلات Fanout