Transacciones frente a confirmaciones del publisher
Compare las transacciones de AMQP con el mecanismo más ligero de confirmaciones del publisher y aprenda cuándo garantiza cada uno que el broker ha aceptado un mensaje de forma segura.
Transacciones frente a confirmaciones del publisher es una lección gratuita de RabbitMQ Messaging & Async Systems en CoddyKit. Esta es la lección 4 de 4. Puedes leer la lección completa abajo gratuitamente — luego la practicas en el navegador con un editor de código integrado y un tutor de IA 24/7. Forma parte de la ruta de aprendizaje de RabbitMQ Messaging & Async Systems, y tu progreso se sincroniza en la web y la app de CoddyKit. El curso de RabbitMQ Messaging & Async Systems incluye 4 lecciones en total.
Partes de esta lección aún no han sido traducidas y se muestran en inglés.
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.
Preguntas frecuentes
¿La lección «Transacciones frente a confirmaciones del publisher» es gratis?
Sí — el texto completo de «Transacciones frente a confirmaciones del publisher» es gratis para leer aquí en la web. Para practicarla de forma interactiva (editor de código integrado y tutor de IA 24/7) y desbloquear el resto del curso de RabbitMQ Messaging & Async Systems, actualiza a CoddyKit PRO. El curso de RabbitMQ Messaging & Async Systems incluye 4 lecciones en total.
¿Qué aprenderé en «Transacciones frente a confirmaciones del publisher»?
Compare las transacciones de AMQP con el mecanismo más ligero de confirmaciones del publisher y aprenda cuándo garantiza cada uno que el broker ha aceptado un mensaje de forma segura. Practicas RabbitMQ Messaging & Async Systems con código real que ejecutas directamente en el navegador, y un tutor de IA 24/7 responde tus preguntas mientras trabajas en la lección.
¿Necesito experiencia previa para empezar RabbitMQ Messaging & Async Systems?
No se requiere experiencia previa. RabbitMQ Messaging & Async Systems en CoddyKit está estructurado para principiantes hasta estudiantes avanzados, así que puedes empezar aquí o desde el inicio y avanzar a tu ritmo. Esta es la lección 4 de 4.
¿Cuánto tiempo toma la lección «Transacciones frente a confirmaciones del publisher»?
La mayoría de las lecciones de CoddyKit toman alrededor de 5–10 minutos. Cada una es compacta e interactiva, así que avanzas constantemente y retomas exactamente por donde dejaste en la web y la app.
¿Puedo escribir y ejecutar código en esta lección de RabbitMQ Messaging & Async Systems?
Sí. Cada lección de RabbitMQ Messaging & Async Systems incluye un editor de código integrado, así que escribes y ejecutas código real directamente en tu navegador y obtienes retroalimentación instantánea de IA — sin configuración local necesaria.
Todas las lecciones de este curso
- Mensajes y colas persistentes
- Confirmaciones del publicador para mayor fiabilidad
- Confirmaciones y reencolado de consumidores
- Transacciones frente a confirmaciones del publisher