activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r1695609 - in /activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src: main/csharp/MessageConsumer.cs test/csharp/QueueBrowserTests.cs
Date Wed, 12 Aug 2015 21:05:05 GMT
Author: tabish
Date: Wed Aug 12 21:05:05 2015
New Revision: 1695609

URL: http://svn.apache.org/r1695609
Log:
Ensure that a QueueBrowser does not filter expired messages, instead deliver the complete
Queue snapshot.
Fixes [AMQNET-AMQNET-505]. (See https://issues.apache.org/jira/browse/AMQNET-AMQNET-505)

Modified:
    activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/MessageConsumer.cs
    activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/QueueBrowserTests.cs

Modified: activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/MessageConsumer.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/MessageConsumer.cs?rev=1695609&r1=1695608&r2=1695609&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/MessageConsumer.cs
(original)
+++ activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/MessageConsumer.cs
Wed Aug 12 21:05:05 2015
@@ -1035,7 +1035,7 @@ namespace Apache.NMS.ActiveMQ
                 {
                     return null;
                 }
-                else if(!IgnoreExpiration && dispatch.Message.IsExpired())
+                else if(ConsumeExpiredMessage(dispatch))
                 {
                     Tracer.DebugFormat("Consumer[{0}] received expired message: {1}",
                                        ConsumerId, dispatch.Message.MessageId);
@@ -1073,6 +1073,16 @@ namespace Apache.NMS.ActiveMQ
             }
         }
 
+        private bool ConsumeExpiredMessage(MessageDispatch dispatch) 
+        {
+            if (dispatch.Message.IsExpired()) 
+            {
+                return !info.Browser && !IgnoreExpiration;
+            }
+
+            return false;
+        }
+
         public virtual void BeforeMessageIsConsumed(MessageDispatch dispatch)
         {
             dispatch.DeliverySequenceId = session.NextDeliveryId;

Modified: activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/QueueBrowserTests.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/QueueBrowserTests.cs?rev=1695609&r1=1695608&r2=1695609&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/QueueBrowserTests.cs
(original)
+++ activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/QueueBrowserTests.cs
Wed Aug 12 21:05:05 2015
@@ -205,6 +205,76 @@ namespace Apache.NMS.ActiveMQ.Test
                 IQueueBrowser browser = session.CreateBrowser(queue);
 				browser.Close();
             }
-        }		
+        }
+
+        [Test]
+        public void TestBrowsingExpiration()
+        {
+            const int MESSAGES_TO_SEND = 50;
+            const string QUEUE_NAME = "TEST.TestBrowsingExpiration";
+
+            SendTestMessages(MESSAGES_TO_SEND, QUEUE_NAME);
+
+            // Browse the queue.
+            using (Connection connection = CreateConnection() as Connection)
+            using (ISession session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge))
+            {
+                connection.Start();
+                int browsed = Browse(QUEUE_NAME, connection);
+
+                // The number of messages browsed should be equal to the number of
+                // messages sent.
+                Assert.AreEqual(MESSAGES_TO_SEND, browsed);
+
+                // Broker expired message period is 30 seconds by default
+                for (int i = 0; i < 12; ++i)
+                {
+                    Thread.Sleep(5000);
+                    browsed = Browse(QUEUE_NAME, connection);
+                }
+
+                session.DeleteDestination(session.GetQueue(QUEUE_NAME));
+
+                Assert.AreEqual(0, browsed);
+            }
+        }
+
+        private int Browse(String queueName, Connection connection)
+        {
+            int browsed = 0;
+
+            using (ISession session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge))
+            using (IQueue queue = session.GetQueue(queueName))
+            using (IQueueBrowser browser = session.CreateBrowser(queue))
+            {
+                IEnumerator enumeration = browser.GetEnumerator();
+                while (enumeration.MoveNext())
+                {
+                    ITextMessage message = enumeration.Current as ITextMessage;
+                    browsed++;
+                }
+            }
+
+            return browsed;
+        }
+
+        protected void SendTestMessages(int count, String queueName)
+        {
+            // Send the messages to the Queue.
+            using (Connection connection = CreateConnection() as Connection)
+            using (ISession session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge))
+            using (IQueue queue = session.GetQueue(queueName))
+            using (IMessageProducer producer = session.CreateProducer(queue))
+            {
+                for (int i = 1; i <= count; i++) 
+                {
+                    String msgStr = "Message: " + i;
+                    producer.Send(session.CreateTextMessage(msgStr), 
+                                  MsgDeliveryMode.NonPersistent, 
+                                  MsgPriority.Normal, 
+                                  TimeSpan.FromMilliseconds(1500));
+                }
+            }
+        }
 	}
 }



Mime
View raw message