Need help on MSMQ and DTC

  • Thread starter Thread starter MarcoB
  • Start date Start date
M

MarcoB

I am using message queue and would like to put the message back into the
queue in case a database transaction did not succeed. The only way I see
this is:

1)using peek and then removing the message from the queue based on the
database transaction results.
2)I assume DTC (COM+) would take care of this coordinating the queue and
the database transactions.

I have looked on the web for information on this, but was did not find much
on dot net using DTC. Is there a better alternative? If yes, is there a
sample code and documentation I could look at ?

Thanks in advance
--Marc
 
Marc,
I am using message queue and would like to put the message back into the
queue in case a database transaction did not succeed. The only way I see
this is:

1)using peek and then removing the message from the queue based on the
database transaction results.
2)I assume DTC (COM+) would take care of this coordinating the queue and
the database transactions.

The second one would really be the only sane option.
I have looked on the web for information on this, but was did not find much
on dot net using DTC. Is there a better alternative? If yes, is there a
sample code and documentation I could look at ?

Look at the docs on using ServicedComponents. Basically, what you'll want is
to write a Serviced Component that has transactions enabled
(TransactionOption.Required or similar), and that reads the message from the
queue, and writes to the database, and let COM+ abort the distributed
transaction on error.

This article contains an example of doing something similar to what you
want:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnbda/html/bdadotnetasync2.asp
 
Don't cross post. There's no need to send this to all these newsgroups!

You should read the message rather than peek it. The assumption is that if
all goes well, the message is gone. Use a catch block for failed attempts in
the database or where ever. On failure, put the message back in the queue in
the catch block for reprocessing.
 
Back
Top