[rabbitmq-discuss] publishing inside a transaction before acking

Michael Bridgen mikeb at rabbitmq.com
Tue May 18 12:04:15 BST 2010


vishnu wrote:
> we have scenarios where we pick up a message at a time, perform a bunch 
> of operations, publish a new message and then ack the message we just 
> picked up. Recently we have started to publish the new message inside a 
> transaction since this guarantees that the message is persisted (it's a 
> persistent message), since we want to minimize the odds of message loss. 
> However, we have started to notice that the original message we pick up 
> is marked as unacknowledged after we complete our process. Is there 
> something fundamentally wrong in what we're doing, or is our approach 
> correct?

The approach is correct.  What order are you doing things in?
Transactions are implicitly started immediately after a commit or
rollback, and acknowledgements are transactional, so if you're
committing after the publish but before the ack --

basic.publish(new_message)
tx.commit()
basic.ack(old_message)

the state at this point is a published message, and an uncommitted
transaction with the ack.  If you do this:

basic.publish(new_message)
basic.ack(old_message)
tx.commit()

then you'll have atomically acked the old message and published the new
one; which is, I believe, what you want.


Michael.




More information about the rabbitmq-discuss mailing list