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/08 20:51:29 UTC

svn commit: r1689933 - in /activemq/activemq-dotnet/Apache.NMS.WCF/branches/1.7.x/src/main/csharp: NmsInputChannelListener.cs NmsInputSessionChannelListener.cs NmsOutputChannel.cs

Author: jgomes
Date: Wed Jul  8 18:51:28 2015
New Revision: 1689933

URL: http://svn.apache.org/r1689933
Log:
Applied patch to keep the session object alive during transactions. Thanks, Andrea Montemaggio!
Fixes [AMQNET-398]. (See https://issues.apache.org/jira/browse/AMQNET-398)

Modified:
    activemq/activemq-dotnet/Apache.NMS.WCF/branches/1.7.x/src/main/csharp/NmsInputChannelListener.cs
    activemq/activemq-dotnet/Apache.NMS.WCF/branches/1.7.x/src/main/csharp/NmsInputSessionChannelListener.cs
    activemq/activemq-dotnet/Apache.NMS.WCF/branches/1.7.x/src/main/csharp/NmsOutputChannel.cs

Modified: activemq/activemq-dotnet/Apache.NMS.WCF/branches/1.7.x/src/main/csharp/NmsInputChannelListener.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.WCF/branches/1.7.x/src/main/csharp/NmsInputChannelListener.cs?rev=1689933&r1=1689932&r2=1689933&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.WCF/branches/1.7.x/src/main/csharp/NmsInputChannelListener.cs (original)
+++ activemq/activemq-dotnet/Apache.NMS.WCF/branches/1.7.x/src/main/csharp/NmsInputChannelListener.cs Wed Jul  8 18:51:28 2015
@@ -324,15 +324,6 @@ namespace Apache.NMS.WCF
 		#endregion
 
 		/// <summary>
-		/// Dispatches the callback.
-		/// </summary>
-		/// <param name="state">The state.</param>
-		internal void DispatchCallback(object state)
-		{
-			Dispatch((Message) state);
-		}
-
-		/// <summary>
 		/// Matches an incoming message to its waiting listener,
 		/// using the FilterTable to dispatch the message to the correct
 		/// listener. If no listener is waiting for the message, it is silently
@@ -363,6 +354,10 @@ namespace Apache.NMS.WCF
 			catch(Exception e)
 			{
 				Tracer.ErrorFormat("Error dispatching Message: {0}", e.ToString());
+				if(null != _session && _session.Transacted)
+				{
+					throw;
+				}
 			}
 		}
 

Modified: activemq/activemq-dotnet/Apache.NMS.WCF/branches/1.7.x/src/main/csharp/NmsInputSessionChannelListener.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.WCF/branches/1.7.x/src/main/csharp/NmsInputSessionChannelListener.cs?rev=1689933&r1=1689932&r2=1689933&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.WCF/branches/1.7.x/src/main/csharp/NmsInputSessionChannelListener.cs (original)
+++ activemq/activemq-dotnet/Apache.NMS.WCF/branches/1.7.x/src/main/csharp/NmsInputSessionChannelListener.cs Wed Jul  8 18:51:28 2015
@@ -324,15 +324,6 @@ namespace Apache.NMS.WCF
 		#endregion
 
 		/// <summary>
-		/// Dispatches the callback.
-		/// </summary>
-		/// <param name="state">The state.</param>
-		internal void DispatchCallback(object state)
-		{
-			Dispatch((Message) state);
-		}
-
-		/// <summary>
 		/// Matches an incoming message to its waiting listener,
 		/// using the FilterTable to dispatch the message to the correct
 		/// listener. If no listener is waiting for the message, it is silently

Modified: activemq/activemq-dotnet/Apache.NMS.WCF/branches/1.7.x/src/main/csharp/NmsOutputChannel.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.WCF/branches/1.7.x/src/main/csharp/NmsOutputChannel.cs?rev=1689933&r1=1689932&r2=1689933&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.WCF/branches/1.7.x/src/main/csharp/NmsOutputChannel.cs (original)
+++ activemq/activemq-dotnet/Apache.NMS.WCF/branches/1.7.x/src/main/csharp/NmsOutputChannel.cs Wed Jul  8 18:51:28 2015
@@ -71,23 +71,47 @@ namespace Apache.NMS.WCF
 			ThrowIfDisposedOrNotOpen();
 			RemoteAddress.ApplyTo(message);
 
-			using(NMS.ISession session = _connection.CreateSession())
+			NMS.ISession session = _connection.CreateSession();
+
+			if(!session.Transacted)
+ 			{
+				using(session)
+ 				{
+					DoSendMessageForSession(session, message);
+ 				}
+ 			}
+			else
 			{
-				IDestination destination = SessionUtil.GetDestination(session, Destination, DestinationType);
-				using(IMessageProducer producer = session.CreateProducer(destination))
-				{
-					producer.DeliveryMode = MsgDeliveryMode.Persistent;
-
-					ITextMessage request = session.CreateTextMessage(TranslateMessage(message));
-					producer.Send(request);
-					producer.Close();
-
-					Tracer.Info("Sending message:");
-					Tracer.Info(request.Text);
-				}
+				// we are inside a transaction, so we should defer session disposing until transaction ends
+				session.TransactionCommittedListener += SessionOnTransactionEndHandler;
+				session.TransactionRolledBackListener += SessionOnTransactionEndHandler;
+				DoSendMessageForSession(session, message);
 			}
 		}
 
+		private void SessionOnTransactionEndHandler(ISession session)
+		{
+			session.TransactionCommittedListener -= SessionOnTransactionEndHandler;
+			session.TransactionRolledBackListener -= SessionOnTransactionEndHandler;
+			session.Dispose();
+		}
+
+		private void DoSendMessageForSession(ISession session, Message message)
+		{
+			IDestination destination = SessionUtil.GetDestination(session, Destination, DestinationType);
+			using (IMessageProducer producer = session.CreateProducer(destination))
+			{
+				producer.DeliveryMode = MsgDeliveryMode.Persistent;
+
+				ITextMessage request = session.CreateTextMessage(TranslateMessage(message));
+				producer.Send(request);
+				producer.Close();
+
+				Tracer.Info("Sending message:");
+				Tracer.Info(request.Text);
+			}			
+		}
+
 		/// <summary>
 		/// Translates the message using the appropriate SOAP versioning scheme.
 		/// </summary>