0Pricing
RabbitMQ Messaging & Async Systems · Lezione

Transazioni e publisher confirms

Confronti le transazioni AMQP con il meccanismo più leggero dei publisher confirms e impari quando ciascuno garantisce che un messaggio sia stato accettato in sicurezza dal broker.

Transazioni e publisher confirms è una lezione RabbitMQ Messaging & Async Systems gratuita su CoddyKit. Questa è la lezione 4 di 4. Puoi leggere la lezione completa qui gratuitamente — poi esercitati direttamente nel browser con un editor di codice integrato e un tutor IA disponibile 24/7. Fa parte del percorso di apprendimento RabbitMQ Messaging & Async Systems, e i tuoi progressi si sincronizzano tra il web e l'app CoddyKit. Il corso RabbitMQ Messaging & Async Systems include 4 lezioni in totale.

Parti di questa lezione non sono ancora state tradotte e vengono mostrate in inglese.

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.

Domande Frequenti

La lezione «Transazioni e publisher confirms» è gratuita?

Sì — il testo completo di «Transazioni e publisher confirms» è gratuito qui sul web. Per esercitarvi in modo interattivo (un editor di codice integrato e un tutor IA 24/7) e sbloccare il resto del corso RabbitMQ Messaging & Async Systems, passa a CoddyKit PRO. Il corso RabbitMQ Messaging & Async Systems include 4 lezioni in totale.

Cosa imparerò in «Transazioni e publisher confirms»?

Confronti le transazioni AMQP con il meccanismo più leggero dei publisher confirms e impari quando ciascuno garantisce che un messaggio sia stato accettato in sicurezza dal broker. Eserciti RabbitMQ Messaging & Async Systems con codice pratico che esegui direttamente nel browser, e un tutor IA 24/7 risponde alle tue domande mentre lavori sulla lezione.

Ho bisogno di esperienza per iniziare RabbitMQ Messaging & Async Systems?

Non è richiesta alcuna esperienza precedente. RabbitMQ Messaging & Async Systems su CoddyKit è strutturato per principianti e studenti avanzati, quindi puoi iniziare da qui o dall'inizio e procedere al tuo ritmo. Questa è la lezione 4 di 4.

Quanto tempo richiede la lezione «Transazioni e publisher confirms»?

La maggior parte delle lezioni CoddyKit richiede circa 5–10 minuti. Ogni lezione è breve e interattiva, quindi fai progressi costanti e riprendi esattamente da dove hai lasciato su web e app.

Posso scrivere ed eseguire codice in questa lezione RabbitMQ Messaging & Async Systems?

Sì. Ogni lezione RabbitMQ Messaging & Async Systems include un editor di codice integrato, quindi scrivi ed esegui codice reale direttamente nel tuo browser e ricevi feedback istantaneo dall'IA — nessuna configurazione locale necessaria.

Tutte le lezioni di questo corso

  1. Messaggi e code persistenti
  2. Conferme del publisher per l'affidabilità
  3. Conferme dei consumer e reinserimento in coda
  4. Transazioni e publisher confirms
← Torna a RabbitMQ Messaging & Async Systems