﻿<?xml version="1.0" encoding="utf-8"?><rss version="2.0"><channel><title>Ayende @ Rahien</title><link>http://ayende.com</link><description>Ayende @ Rahien</description><copyright>Copyright (C) Ayende Rahien  2004 - 2021 (c) 2026</copyright><ttl>60</ttl><item><title>Ayende Rahien commented on Distributed transactions with remote queuing system</title><description>Maninder,
  
Because I don't want to consume the message on error.
  
I want to put it back on the queue and let the queue poison msg handling to take care of that.
  
This way, I don't lose messages
</description><link>http://ayende.com/4679/distributed-transactions-with-remote-queuing-system#comment13</link><guid>http://ayende.com/4679/distributed-transactions-with-remote-queuing-system#comment13</guid><pubDate>Wed, 03 Nov 2010 16:27:25 GMT</pubDate></item><item><title>Maninder Batth commented on Distributed transactions with remote queuing system</title><description>How about the following :-
  
  
try {
  
	 1. Dequeue
  
  
		try {
  
                   2. Process Message
  
		    } catch (Exception ) {
  
                   3. Message error, ACK and do not queue it back
  
                   4. Internal system error, retry or compensate.
  
			}
  
			try {
  
				5. Commit message processing
  
				} catch (Exception) {
  
				  1. Error while commiting, retry or compensate.
  
				}
  
  
       } catch (Exception )
  
	 {
  
		//Error while Dequeue, retry or compensate.
  
	 }
  
  
	try {
  
		ACK
  
	    } catch (Exception )
  
	    {
  
		// perhaps retry ACK or compensate.
  
	    }
  
Question :- why do you need table for persisting fully processed messages ? 
</description><link>http://ayende.com/4679/distributed-transactions-with-remote-queuing-system#comment12</link><guid>http://ayende.com/4679/distributed-transactions-with-remote-queuing-system#comment12</guid><pubDate>Wed, 03 Nov 2010 16:06:19 GMT</pubDate></item><item><title>Bill commented on Distributed transactions with remote queuing system</title><description>I think the code seems to work. The down side is you have to store some state (processed messages) specific to this problem on the client side but i can't think of a better way of doing it without dtc.
</description><link>http://ayende.com/4679/distributed-transactions-with-remote-queuing-system#comment11</link><guid>http://ayende.com/4679/distributed-transactions-with-remote-queuing-system#comment11</guid><pubDate>Mon, 01 Nov 2010 09:54:18 GMT</pubDate></item><item><title>Ayende Rahien commented on Distributed transactions with remote queuing system</title><description>Alex,
  
The point isn't to import the queue.
  
The point is to process the message just once in a successful transaction
</description><link>http://ayende.com/4679/distributed-transactions-with-remote-queuing-system#comment10</link><guid>http://ayende.com/4679/distributed-transactions-with-remote-queuing-system#comment10</guid><pubDate>Mon, 01 Nov 2010 07:04:07 GMT</pubDate></item><item><title>Alex Yakunin commented on Distributed transactions with remote queuing system</title><description>Oren, I know you like to argue, so let's leave the talk about best practices.
  
  
If your goal is to safely import the external queue to RDBMS as-is, the code seems almost absolutely safe. Btw, you don't need manual transactions at all to achieve this, because if entry isn't imported, it's always safe to re-import it.
  
  
Why "almost"? Well, because there is a cleanup process that removes imported &amp;&amp; processed entries from DB. So there is a tiny chance that entry will be imported and removed, but Ack isn't sent for it (e.g. because queue was dead for enough long time). But practically, this is hardly possible.
</description><link>http://ayende.com/4679/distributed-transactions-with-remote-queuing-system#comment9</link><guid>http://ayende.com/4679/distributed-transactions-with-remote-queuing-system#comment9</guid><pubDate>Sun, 31 Oct 2010 19:25:03 GMT</pubDate></item><item><title>Ayende Rahien commented on Distributed transactions with remote queuing system</title><description>Alex,
  
You can pretty much assume that InsertToProcessedMessages translate to the direct ADO code to call INSERT INTO ProcessedMessages
  
There is generally no option for deadlock on insert and there are certainly no version conflicts for pure inserts.
</description><link>http://ayende.com/4679/distributed-transactions-with-remote-queuing-system#comment8</link><guid>http://ayende.com/4679/distributed-transactions-with-remote-queuing-system#comment8</guid><pubDate>Sun, 31 Oct 2010 17:47:24 GMT</pubDate></item><item><title>Ayende Rahien commented on Distributed transactions with remote queuing system</title><description>Alex,
  
If that is the case, on the next try to read the message, you will hit the DupPK error and ack it then.
</description><link>http://ayende.com/4679/distributed-transactions-with-remote-queuing-system#comment7</link><guid>http://ayende.com/4679/distributed-transactions-with-remote-queuing-system#comment7</guid><pubDate>Sun, 31 Oct 2010 17:46:16 GMT</pubDate></item><item><title>Alex Yakunin commented on Distributed transactions with remote queuing system</title><description>&gt; You can't GET a deadlock from a simple insert when the only things is an insert of a PK.
  
  
First of all, there is no any exact code, so I assumed there is generally anything. 
  
  
I any case, I won't ASSUME there is just an INSERT even if I'd know this precisely. That's simply a bad practice: the DB-related code based on implication there can be just one kind of exception, and no deadlocks \ version conflicts might lead to completely unexpected issues in future, since the author maintaining InsertToProcessedMessages might not be aware of these implications of its callers .
</description><link>http://ayende.com/4679/distributed-transactions-with-remote-queuing-system#comment6</link><guid>http://ayende.com/4679/distributed-transactions-with-remote-queuing-system#comment6</guid><pubDate>Sun, 31 Oct 2010 17:02:01 GMT</pubDate></item><item><title>Alex Yakunin commented on Distributed transactions with remote queuing system</title><description>Ups, initially I didn't fully understand the logic of this code, so ignore my previous comment.
  
  
IMO, it has just one lack, that will lead to an issue in this case:
  
- SQL Server actually commits the transaction as result of tx.Commit() call
  
- But something (e.g. network issue) prevent SQL client from returning correct completion code of this operation.
  
  
In this case your code will re-process the message, that actually was already processed.
</description><link>http://ayende.com/4679/distributed-transactions-with-remote-queuing-system#comment5</link><guid>http://ayende.com/4679/distributed-transactions-with-remote-queuing-system#comment5</guid><pubDate>Sun, 31 Oct 2010 16:53:49 GMT</pubDate></item><item><title>Ayende Rahien commented on Distributed transactions with remote queuing system</title><description>Alex,
  
You can't GET a deadlock from a simple insert when the only things is an insert of a PK.
  
</description><link>http://ayende.com/4679/distributed-transactions-with-remote-queuing-system#comment4</link><guid>http://ayende.com/4679/distributed-transactions-with-remote-queuing-system#comment4</guid><pubDate>Sun, 31 Oct 2010 16:51:31 GMT</pubDate></item><item><title>Alex Yakunin commented on Distributed transactions with remote queuing system</title><description>"catch (DuplicatePrimaryKey)" does not ensures all errors are processed. E.g. deadlock exception won't be handled by this code. As result, Ack won't be invoked at all.
  
  
Another case is when  tx.Commit() throws an exception. Generally, by the same reason; also, some DBs may check constraints with delay, so actually a wide range of exceptions is possible there, and everything depends on a particular case. If an exception is thrown by tx.Commit(), Ack won't be invoked again.
</description><link>http://ayende.com/4679/distributed-transactions-with-remote-queuing-system#comment3</link><guid>http://ayende.com/4679/distributed-transactions-with-remote-queuing-system#comment3</guid><pubDate>Sun, 31 Oct 2010 16:48:57 GMT</pubDate></item><item><title>Ayende Rahien commented on Distributed transactions with remote queuing system</title><description>Josehph,
  
SQL Server Service Broker is a local queue, from a conceptual model.
  
The problem is that it is very likely that Send / Receive to the queue will fail if it is stored on remote machine.
  
It mostly depends on the deployment mode.
</description><link>http://ayende.com/4679/distributed-transactions-with-remote-queuing-system#comment2</link><guid>http://ayende.com/4679/distributed-transactions-with-remote-queuing-system#comment2</guid><pubDate>Sun, 31 Oct 2010 16:29:19 GMT</pubDate></item><item><title>Joseph Daigle commented on Distributed transactions with remote queuing system</title><description>What about a transactional remote queue like SQL Server Service Broker? In this case you receive a message inside a transaction, the message is dequeued, and if the transaction is rolled back for any reason the message is re-queued.
  
  
The guidance is that your Service Broker database and application transaction database should be separate. Therefore you would employ the DTC to get transactional consistency between your application database and your remote queue.
  
  
There's no need to keep track of which messages were processed as it will never be handled more than once (such that data is written to the application database).
</description><link>http://ayende.com/4679/distributed-transactions-with-remote-queuing-system#comment1</link><guid>http://ayende.com/4679/distributed-transactions-with-remote-queuing-system#comment1</guid><pubDate>Sun, 31 Oct 2010 15:21:00 GMT</pubDate></item></channel></rss>