[rabbitmq-discuss] database transaction
Tomek Rozen
tomek.rozen+rabbitmq at gmail.com
Thu Mar 18 08:07:58 GMT 2010
Hi Matthew,
Matthew Sackman wrote:
>
> Hi Tomek,
>
> 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!
>
>
This was my initial approach. Unfortunately it requires the mentioned
"extra logic", which must be implemented for all types of objects you
want to serialize.
If there was some kind of ID on each message then the ID could be
saved in the DB on the same transaction as the message's object. Then
duplicates could be filtered on a per-message basis, as opposed to per
object. However, I'm not aware of any kind of a message ID in rabbit
that could be used. Can you think of anything?
> 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
> it.
>
>
I wasn't aware of this. Thank you.
Tomek
--
View this message in context: http://old.nabble.com/database-transaction-tp27932801p27942664.html
Sent from the RabbitMQ mailing list archive at Nabble.com.
More information about the rabbitmq-discuss
mailing list