نمط صندوق الصادر للنشر الموثوق
تعلّم نمط صندوق الصادر المعاملاتي لتنفيذ حالة العمل والرسائل الصادرة ذريًا، والتخلّص من مشكلة الكتابة المزدوجة في الأنظمة القائمة على الأحداث.
نمط صندوق الصادر للنشر الموثوق درس مجاني في RabbitMQ Messaging & Async Systems على CoddyKit. هذا هو الدرس 4 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في RabbitMQ Messaging & Async Systems، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة RabbitMQ Messaging & Async Systems 4 دروس في المجموع.
بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.
The Dual-Write Problem
Saving to a database and publishing to RabbitMQ are two separate operations. If one succeeds and the other fails, your state and your events drift apart.
This is the dual-write problem.
What Is the Outbox Pattern?
The outbox pattern writes the business change and the outgoing message into the same database transaction, then publishes the message asynchronously from the outbox table.
The Outbox Table
Create a table that stores pending messages alongside your domain data.
CREATE TABLE outbox (
id UUID PRIMARY KEY,
payload JSONB,
published BOOLEAN DEFAULT FALSE,
created_at TIMESTAMPTZ DEFAULT now()
);Atomic Write
In one transaction, update the business row and insert the outbox row. Either both commit or neither does.
BEGIN;
INSERT INTO orders (id, status) VALUES ('42', 'paid');
INSERT INTO outbox (id, payload) VALUES (gen_random_uuid(), '{"order":"42"}');
COMMIT;The Relay Process
A separate relay (or message dispatcher) polls the outbox for unpublished rows, publishes them to RabbitMQ, and marks them published.
Polling the Outbox
The relay selects pending rows in order and publishes each one.
SELECT id, payload FROM outbox WHERE published = FALSE ORDER BY created_at;At-Least-Once Delivery
If the relay crashes after publishing but before marking the row, it republishes on restart. So consumers must be idempotent to tolerate duplicates.
Change Data Capture Alternative
Instead of polling, tools like Debezium tail the database write-ahead log and stream outbox inserts to RabbitMQ, reducing latency and load.
Combining With Confirms
The relay should use publisher confirms so it only marks a row published after the broker acknowledges the message, closing the loss window.
Outbox vs Saga
The outbox guarantees a single service reliably emits its events. A saga coordinates a multi-service workflow. They complement each other: each saga step can publish via its own outbox.
Cleanup and Retention
- Periodically delete or archive published rows
- Index on
publishedfor fast polling - Monitor relay lag to catch stalls early
Quick Check
Test your outbox understanding.
Recap
The outbox pattern stores outgoing messages in the same transaction as business data, then a relay publishes them to RabbitMQ asynchronously.
It eliminates the dual-write problem, requires idempotent consumers due to at-least-once delivery, and pairs well with publisher confirms and sagas.
الأسئلة الشائعة
هل درس «نمط صندوق الصادر للنشر الموثوق» مجاني؟
نعم — نص درس «نمط صندوق الصادر للنشر الموثوق» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة RabbitMQ Messaging & Async Systems، انتقل إلى CoddyKit PRO. تتضمن دورة RabbitMQ Messaging & Async Systems 4 دروس في المجموع.
ماذا ستتعلم في «نمط صندوق الصادر للنشر الموثوق»؟
تعلّم نمط صندوق الصادر المعاملاتي لتنفيذ حالة العمل والرسائل الصادرة ذريًا، والتخلّص من مشكلة الكتابة المزدوجة في الأنظمة القائمة على الأحداث. تتمرن على RabbitMQ Messaging & Async Systems مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.
هل أحتاج إلى خبرة سابقة لأبدأ RabbitMQ Messaging & Async Systems؟
لا تُشترط خبرة سابقة. RabbitMQ Messaging & Async Systems على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 4 من أصل 4.
كم من الوقت يستغرق درس «نمط صندوق الصادر للنشر الموثوق»؟
معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.
هل يمكنني كتابة وتشغيل أكواد في درس RabbitMQ Messaging & Async Systems هذا؟
نعم. كل درس في RabbitMQ Messaging & Async Systems يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.
جميع الدروس في هذه الدورة
- خاصية عدم التكرار في معالجة الرسائل
- نمط Saga مع RabbitMQ
- فصل مسؤولية الأوامر والاستعلامات (CQRS)
- نمط صندوق الصادر للنشر الموثوق