[rabbitmq-discuss] database transaction
matthew at lshift.net
Wed Mar 17 15:00:57 GMT 2010
On Wed, Mar 17, 2010 at 07:54:10AM -0700, Tomek Rozen wrote:
> Let's say that I have a consumer on a single queue. Every message read from
> the queue is stored to a database and ACKed.
> What is the general approach to assuring that in case of failure either the
> message is saved and ack'ed OR nothing is written to DB and the message
> remains in the queue.
Really, you want a distributed transaction here, which can't be done.
I would suggest that you insert into the database, when you know that's
there, do the ack. That leaves you open to the possibility of receiving
the message again if the client crashes or the ack message gets lost,
thus you may need some extra logic in the client to try to detect if a
message is already in the database. If you have the possibility that you
may find, on a redelivery, that the message is not in the database
because some other process has deleted it since, then you're going to
struggle at this point!
Also note that delivery messages have a redelivered flag. If this is 0
(or false), Rabbit is guaranteeing to you that the message has not
previously been delivered (hence you can skip duplicate tests here). If
it's 1, then Rabbit is saying it *may* have been already delivered to
you before, so you should check to see whether you've already received
Hope that helps,
More information about the rabbitmq-discuss