Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TransactionScope elevating to MSDTC when sending between queues?

I have a simple process which reads from one queue, processes the messages, and outputs to another. I am trying to wrap this transfer within a TransactionScope, such that both the read from the input queue, and the write to the output queue occurs within the same transaction.

However, it would appear that MSDTC is being used to conduct this transaction, and as a result it is significantly slower than using a standard MessageQueueTransaction. Should this be happening? I was under the impression that TransactionScope would only elevate to an external transaction if the scope involved, for instance, a message queue read, and a database write, but not if just multiple message queues were involved.

Thanks.

EDIT: This is all on my laptop at the moment, so I am sure that no other machines are involved.

I also want to add that I'm confirming that an escalated transaction is taking place by checking in Windows' 'Component Services' snap-in (i.e. the Local DTC / Transaction List). I can see the transactions entering and leaving this screen, which I assume means that the transaction has been escalated. Am I wrong in assuming this?

EDIT 2: I'm getting the same behaviour when I am just writing to a single queue! i.e.

using (var ts = new TransactionScope())
{
    using (var q = new MessageQueue("..."))
    {
        /* write data */
    }

    ts.Complete();
}

I can see the DTC being used with the above, despite the queue being on the local machine.

like image 671
Barguast Avatar asked Oct 23 '22 09:10

Barguast


1 Answers

It seems TransactionScope only handles external transactions in respect to message queues. You have to use MessageQueueTransaction if you want it to be internal only. This works differently with SQL transactions where the transaction is only escalated if required, which is what confused me.

like image 127
Barguast Avatar answered Oct 27 '22 00:10

Barguast