Author: jgomes
Date: Wed Jul  8 18:52:56 2015
New Revision: 1689934

URL: http://svn.apache.org/r1689934
Log:
Merged revision(s) 1689933 from 
activemq/activemq-dotnet/Apache.NMS.WCF/branches/1.7.x:
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/trunk/   (props changed)
    
activemq/activemq-dotnet/Apache.NMS.WCF/trunk/src/main/csharp/NmsInputChannelListener.cs
    
activemq/activemq-dotnet/Apache.NMS.WCF/trunk/src/main/csharp/NmsInputSessionChannelListener.cs
    
activemq/activemq-dotnet/Apache.NMS.WCF/trunk/src/main/csharp/NmsOutputChannel.cs

Propchange: activemq/activemq-dotnet/Apache.NMS.WCF/trunk/
------------------------------------------------------------------------------
--- svn:mergeinfo (added)
+++ svn:mergeinfo Wed Jul  8 18:52:56 2015
@@ -0,0 +1 @@
+/activemq/activemq-dotnet/Apache.NMS.WCF/branches/1.7.x:1689933

Modified: 
activemq/activemq-dotnet/Apache.NMS.WCF/trunk/src/main/csharp/NmsInputChannelListener.cs
URL: 
http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.WCF/trunk/src/main/csharp/NmsInputChannelListener.cs?rev=1689934&r1=1689933&r2=1689934&view=diff
==============================================================================
--- 
activemq/activemq-dotnet/Apache.NMS.WCF/trunk/src/main/csharp/NmsInputChannelListener.cs
 (original)
+++ 
activemq/activemq-dotnet/Apache.NMS.WCF/trunk/src/main/csharp/NmsInputChannelListener.cs
 Wed Jul  8 18:52:56 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/trunk/src/main/csharp/NmsInputSessionChannelListener.cs
URL: 
http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.WCF/trunk/src/main/csharp/NmsInputSessionChannelListener.cs?rev=1689934&r1=1689933&r2=1689934&view=diff
==============================================================================
--- 
activemq/activemq-dotnet/Apache.NMS.WCF/trunk/src/main/csharp/NmsInputSessionChannelListener.cs
 (original)
+++ 
activemq/activemq-dotnet/Apache.NMS.WCF/trunk/src/main/csharp/NmsInputSessionChannelListener.cs
 Wed Jul  8 18:52:56 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/trunk/src/main/csharp/NmsOutputChannel.cs
URL: 
http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.WCF/trunk/src/main/csharp/NmsOutputChannel.cs?rev=1689934&r1=1689933&r2=1689934&view=diff
==============================================================================
--- 
activemq/activemq-dotnet/Apache.NMS.WCF/trunk/src/main/csharp/NmsOutputChannel.cs
 (original)
+++ 
activemq/activemq-dotnet/Apache.NMS.WCF/trunk/src/main/csharp/NmsOutputChannel.cs
 Wed Jul  8 18:52:56 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>


Reply via email to