Transações versus confirmações de publicação
Compare as transações AMQP com o mecanismo mais leve de confirmações de publicação e aprenda quando cada um garante que uma mensagem foi aceita com segurança pelo agente de mensagens.
Transações versus confirmações de publicação é uma aula grátis de RabbitMQ Messaging & Async Systems no CoddyKit. Esta é a aula 4 de 4. Você pode ler a aula completa abaixo gratuitamente — depois pratica ao vivo no navegador com um editor de código integrado e um tutor de IA 24/7. Faz parte do caminho de aprendizado de RabbitMQ Messaging & Async Systems, e seu progresso é sincronizado entre a web e o app CoddyKit. O curso de RabbitMQ Messaging & Async Systems inclui 4 aulas no total.
Partes desta aula ainda não foram traduzidas e aparecem em 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.
Perguntas Frequentes
A aula “Transações versus confirmações de publicação” é grátis?
Sim — o texto completo de “Transações versus confirmações de publicação” é grátis para ler aqui na web. Para praticá-la interativamente (um editor de código integrado e um tutor de IA 24/7) e desbloquear o restante do curso de RabbitMQ Messaging & Async Systems, atualize para CoddyKit PRO. O curso de RabbitMQ Messaging & Async Systems inclui 4 aulas no total.
O que vou aprender em “Transações versus confirmações de publicação”?
Compare as transações AMQP com o mecanismo mais leve de confirmações de publicação e aprenda quando cada um garante que uma mensagem foi aceita com segurança pelo agente de mensagens. Você pratica RabbitMQ Messaging & Async Systems com código prático que executa diretamente no navegador, e um tutor de IA 24/7 responde suas dúvidas enquanto trabalha na aula.
Preciso ter experiência prévia para começar RabbitMQ Messaging & Async Systems?
Nenhuma experiência prévia é necessária. RabbitMQ Messaging & Async Systems no CoddyKit é estruturado para alunos iniciantes até avançados, então você pode começar aqui ou desde o início e aprender no seu ritmo. Esta é a aula 4 de 4.
Quanto tempo leva a aula “Transações versus confirmações de publicação”?
A maioria das aulas CoddyKit leva cerca de 5–10 minutos. Cada uma é compacta e interativa, então você faz progresso constante e retoma exatamente de onde parou entre web e app.
Posso escrever e executar código nesta aula de RabbitMQ Messaging & Async Systems?
Sim. Cada aula de RabbitMQ Messaging & Async Systems inclui um editor de código integrado, então você escreve e executa código real direto no navegador e recebe feedback de IA instantaneamente — nenhuma configuração local necessária.
Todas as aulas deste curso
- Mensagens e filas persistentes
- Confirmações do publicador para maior confiabilidade
- Confirmações e reenfileiramento de consumidores
- Transações versus confirmações de publicação