You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by jg...@apache.org on 2015/07/07 00:41:42 UTC

svn commit: r1689517 - in /activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src: main/csharp/NetTxConnection.cs main/csharp/NetTxMessageConsumer.cs main/csharp/NetTxSession.cs test/csharp/DtcTransactionsTestSupport.cs

Author: jgomes
Date: Mon Jul  6 22:41:41 2015
New Revision: 1689517

URL: http://svn.apache.org/r1689517
Log:
Apply patch from Jose Alvarado. Thanks, Jose!
Fixes [AMQNET-503]. (See https://issues.apache.org/jira/browse/AMQNET-503)

Modified:
    activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/NetTxConnection.cs
    activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/NetTxMessageConsumer.cs
    activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/NetTxSession.cs
    activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/DtcTransactionsTestSupport.cs

Modified: activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/NetTxConnection.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/NetTxConnection.cs?rev=1689517&r1=1689516&r2=1689517&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/NetTxConnection.cs (original)
+++ activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/NetTxConnection.cs Mon Jul  6 22:41:41 2015
@@ -51,6 +51,21 @@ namespace Apache.NMS.ActiveMQ
             return session;
         }
 
+        public INetTxSession CreateNetTxSession(Transaction tx, bool enlistNativeMsDtcResource)
+        {
+            NetTxSession session = (NetTxSession)CreateSession(AcknowledgementMode.Transactional);
+            session.Enlist(tx);
+            session.EnlistsMsDtcNativeResource = enlistNativeMsDtcResource;
+            return session;
+        }
+
+        public INetTxSession CreateNetTxSession(bool enlistNativeMsDtcResource)
+        {
+            NetTxSession session = (NetTxSession)CreateSession(AcknowledgementMode.Transactional);
+            session.EnlistsMsDtcNativeResource = enlistNativeMsDtcResource;
+            return session;
+        }
+
         protected override Session CreateActiveMQSession(AcknowledgementMode ackMode)
         {
             CheckConnected();

Modified: activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/NetTxMessageConsumer.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/NetTxMessageConsumer.cs?rev=1689517&r1=1689516&r2=1689517&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/NetTxMessageConsumer.cs (original)
+++ activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/NetTxMessageConsumer.cs Mon Jul  6 22:41:41 2015
@@ -18,6 +18,7 @@
 using System;
 using System.Collections.Generic;
 using System.Text;
+using System.Transactions;
 using Apache.NMS.ActiveMQ.Commands;
 
 namespace Apache.NMS.ActiveMQ
@@ -75,9 +76,29 @@ namespace Apache.NMS.ActiveMQ
                         // distributed TX manager we need to wait whenever the TX is being
                         // controlled by the DTC as it completes all operations async and
                         // we cannot start consumption again until all its tasks have completed.)
-                        waitForDtcWaitHandle = this.transactionContext.InNetTransaction &&
-                                               this.transactionContext.NetTxState ==
-                                               NetTxTransactionContext.TxState.Pending;
+                        var currentTransactionId = transactionContext.TransactionId as XATransactionId;
+                        string currentLocalTxId = currentTransactionId != null
+                            ? UTF8Encoding.UTF8.GetString(currentTransactionId.GlobalTransactionId)
+                            : "NONE";
+
+                        if (Transaction.Current != null)
+                        {
+                            waitForDtcWaitHandle = this.transactionContext.InNetTransaction &&
+                                               this.transactionContext.NetTxState == NetTxTransactionContext.TxState.Pending ||
+                                               currentLocalTxId != Transaction.Current.TransactionInformation.LocalIdentifier;
+                        }
+                        else
+                        {
+                            waitForDtcWaitHandle = this.transactionContext.InNetTransaction &&
+                                               this.transactionContext.NetTxState == NetTxTransactionContext.TxState.Pending;
+                        }
+                        
+                    }
+
+                    //if session EnlistMsDtcNativeResource the transaction does not need to wait
+                    if (this.session.EnlistsMsDtcNativeResource)
+                    {
+                        waitForDtcWaitHandle = false;
                     }
 
                     if (waitForDtcWaitHandle)

Modified: activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/NetTxSession.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/NetTxSession.cs?rev=1689517&r1=1689516&r2=1689517&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/NetTxSession.cs (original)
+++ activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/NetTxSession.cs Mon Jul  6 22:41:41 2015
@@ -32,6 +32,7 @@ namespace Apache.NMS.ActiveMQ
         {
             this.transactionContext = TransactionContext as NetTxTransactionContext;
             this.transactionContext.InitializeDtcTxContext();
+            this.enlistMsDtcNativeResources = false;
         }
 
         /// <summary>
@@ -51,6 +52,14 @@ namespace Apache.NMS.ActiveMQ
             this.EnrollInSpecifiedTransaction(tx);
         }
 
+        private bool enlistMsDtcNativeResources;
+
+        public bool EnlistsMsDtcNativeResource
+        {
+            get { return enlistMsDtcNativeResources; }
+            set { enlistMsDtcNativeResources = value; }
+        }
+
         /// <summary>
         /// Reports Transacted whenever there is an Ambient Transaction or the internal
         /// TransactionContext is still involed in a .NET Transaction beyond the lifetime
@@ -173,6 +182,7 @@ namespace Apache.NMS.ActiveMQ
             this.currentTransactionId = tx.TransactionInformation.LocalIdentifier; 
             transactionContext.Begin(tx);
         }
+        
     }
 }
 

Modified: activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/DtcTransactionsTestSupport.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/DtcTransactionsTestSupport.cs?rev=1689517&r1=1689516&r2=1689517&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/DtcTransactionsTestSupport.cs (original)
+++ activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/DtcTransactionsTestSupport.cs Mon Jul  6 22:41:41 2015
@@ -53,7 +53,8 @@ namespace Apache.NMS.ActiveMQ.Test
         private ITrace oldTracer;
 
         protected const string sqlConnectionString =
-            "Data Source=localhost;Initial Catalog=TestDB;User ID=user;Password=password";
+            // "Data Source=localhost;Initial Catalog=TestDB;User ID=user;Password=password";
+            "Data Source=.\\SQLEXPRESS;Initial Catalog=TestDB;Integrated Security = true";
         protected const string testTable = "TestTable";
         protected const string testColumn = "TestID";
         protected const string testQueueName = "TestQueue";
@@ -484,7 +485,7 @@ namespace Apache.NMS.ActiveMQ.Test
         {
             IList entries = ExtractDataSet();
 
-            using (INetTxSession session = connection.CreateNetTxSession())
+            using (INetTxSession session = connection.CreateNetTxSession(true))
             {
                 IQueue queue = session.GetQueue(testQueueName);
 
@@ -531,7 +532,7 @@ namespace Apache.NMS.ActiveMQ.Test
         {
             IList entries = ExtractDataSet();
 
-            using (INetTxSession session = connection.CreateNetTxSession())
+            using (INetTxSession session = connection.CreateNetTxSession(true))
             {
                 IQueue queue = session.GetQueue(testQueueName);
 
@@ -578,7 +579,7 @@ namespace Apache.NMS.ActiveMQ.Test
 
         protected static void ReadFromQueueAndInsertIntoDbWithCommit(INetTxConnection connection)
         {
-            using (INetTxSession session = connection.CreateNetTxSession())
+            using (INetTxSession session = connection.CreateNetTxSession(true))
             {
                 IQueue queue = session.GetQueue(testQueueName);
 
@@ -619,7 +620,7 @@ namespace Apache.NMS.ActiveMQ.Test
 
         protected static void ReadFromQueueAndInsertIntoDbWithScopeAborted(INetTxConnection connection)
         {
-            using (INetTxSession session = connection.CreateNetTxSession())
+            using (INetTxSession session = connection.CreateNetTxSession(true))
             {
                 IQueue queue = session.GetQueue(testQueueName);