0Pricing
RabbitMQ Messaging & Async Systems · درس

المعاملات مقابل تأكيدات الناشر

قارنوا بين معاملات AMQP وآلية تأكيدات الناشر الأخف، وتعلّموا متى تضمن كل منهما قبول الوسيط للرسالة بأمان.

المعاملات مقابل تأكيدات الناشر درس مجاني في RabbitMQ Messaging & Async Systems على CoddyKit. هذا هو الدرس 4 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في RabbitMQ Messaging & Async Systems، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة RabbitMQ Messaging & Async Systems 4 دروس في المجموع.

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

Why Reliability Needs More Than Persistence

Persistent messages survive a broker restart, but persistence alone does not tell the publisher whether the broker actually received and stored the message.

For end-to-end reliability you need confirmation.

AMQP Transactions

AMQP supports transactions on a channel: you begin a transaction, publish messages, then commit. The broker confirms the whole batch atomically.

Using a Transaction

Enable transaction mode with tx_select, publish, then tx_commit.

channel.tx_select()
channel.basic_publish(exchange='', routing_key='jobs', body='task')
channel.tx_commit()

The Cost of Transactions

Transactions are synchronous and slow. Each commit blocks until the broker responds, often cutting throughput by 200x or more.

They serialize publishing, which kills pipelining.

Publisher Confirms Recap

Publisher confirms are an asynchronous alternative. The broker sends an ack per message (or per batch) once it is safely handled, without blocking the publisher.

Enabling Confirm Mode

Put the channel into confirm mode once; you cannot mix it with transaction mode on the same channel.

channel.confirm_delivery()
channel.basic_publish(exchange='', routing_key='jobs', body='task')

Asynchronous Acks

With confirms you can keep publishing while acks arrive in the background, then match acks to delivery tags. This preserves high throughput.

Handling Nacks

If the broker cannot handle a message it sends a nack. Your code must resend or log it. Nacks are rare but signal internal broker errors.

Choosing Between Them

  • Transactions: true atomic multi-message commit, but very slow
  • Confirms: near-equivalent safety with far higher throughput

The RabbitMQ team recommends confirms for almost all cases.

Combine With Persistence

For the strongest guarantee, mark messages persistent and use confirms; the broker only acks a persistent message after it is written to disk.

props = pika.BasicProperties(delivery_mode=2)
channel.basic_publish(exchange='', routing_key='jobs', body='task', properties=props)

Mutually Exclusive Modes

A single channel cannot be in both transaction and confirm mode. Pick one per channel; attempting both raises a channel error.

Quick Check

Test your reliability knowledge.

Recap

Both transactions and publisher confirms tell a publisher the broker accepted a message.

Transactions are atomic but slow; confirms are asynchronous and fast. Combine confirms with persistent messages for the best balance of reliability and performance.

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

هل درس «المعاملات مقابل تأكيدات الناشر» مجاني؟

نعم — نص درس «المعاملات مقابل تأكيدات الناشر» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة RabbitMQ Messaging & Async Systems، انتقل إلى CoddyKit PRO. تتضمن دورة RabbitMQ Messaging & Async Systems 4 دروس في المجموع.

ماذا ستتعلم في «المعاملات مقابل تأكيدات الناشر»؟

قارنوا بين معاملات AMQP وآلية تأكيدات الناشر الأخف، وتعلّموا متى تضمن كل منهما قبول الوسيط للرسالة بأمان. تتمرن على 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 يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.

جميع الدروس في هذه الدورة

  1. الرسائل وقوائم الانتظار المستمرة
  2. تأكيدات الناشر من أجل الموثوقية
  3. إقرارات المستهلك وإعادة وضع الرسائل في قائمة الانتظار
  4. المعاملات مقابل تأكيدات الناشر
← العودة إلى RabbitMQ Messaging & Async Systems