You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by mi...@apache.org on 2019/10/01 21:31:17 UTC

[activemq-nms-amqp] branch master updated: AMQNET-618: Support noLocal filter

This is an automated email from the ASF dual-hosted git repository.

michaelpearce pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/activemq-nms-amqp.git


The following commit(s) were added to refs/heads/master by this push:
     new d3b012f  AMQNET-618: Support noLocal filter
     new 23e34f2  Merge pull request #40 from Havret/support_no_local_message_filter
d3b012f is described below

commit d3b012f1d1710dea1f32a86609c34118c1fde037
Author: Havret <h4...@gmail.com>
AuthorDate: Tue Oct 1 18:58:08 2019 +0200

    AMQNET-618: Support noLocal filter
---
 README.md                                          |  2 +-
 apache-nms-amqp.sln.DotSettings                    |  2 ++
 src/NMS.AMQP/Provider/Amqp/AmqpConsumer.cs         | 12 ++------
 .../Provider/Amqp/Filters/AmqpNmsNoLocalType.cs    | 35 ++++++++++++++++++++++
 .../AmqpTestSupport.cs                             | 17 +++++++++++
 .../NmsMessageConsumerTest.cs                      | 17 +++++++++++
 6 files changed, 74 insertions(+), 11 deletions(-)

diff --git a/README.md b/README.md
index 4d947ad..450c234 100644
--- a/README.md
+++ b/README.md
@@ -62,7 +62,7 @@ So in general most of the top level classes that implement the Apache.NMS interf
 | IMessageProducer | Y * | Anonymous producers are only supported on connections with the ANONYMOUS-RELAY capability. |
 | MsgDeliveryMode.Persistent | Y | Producers will block on send until an outcome is received or will timeout after waiting the RequestTimeout timespan amount. Exceptions may be throw depending on the outcome or if the producer times out. |
 | MsgDeliveryMode.NonPersistent | Y | Producers will not block on send nor expect to receive an outcome. Should an exception be raised from the outcome the exception will be delivered using the the connection ExceptionListener. |
-| IMessageConsumer | Y * | NoLocal filter is not supported. |
+| IMessageConsumer | Y | |
 | Durable Consumers | Y | |
 | IQueueBrowser | N | The provider will throw NotImplementedException for the ISession create methods. |
 | Configurable NMSMessageID and amqp serializtion | N | For future consideration. The prodiver will generate a MessageID from a sequence and serialize it as a string. |
diff --git a/apache-nms-amqp.sln.DotSettings b/apache-nms-amqp.sln.DotSettings
new file mode 100644
index 0000000..69a5afc
--- /dev/null
+++ b/apache-nms-amqp.sln.DotSettings
@@ -0,0 +1,2 @@
+<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
+	<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=JMS/@EntryIndexedValue">JMS</s:String></wpf:ResourceDictionary>
\ No newline at end of file
diff --git a/src/NMS.AMQP/Provider/Amqp/AmqpConsumer.cs b/src/NMS.AMQP/Provider/Amqp/AmqpConsumer.cs
index a238ace..b342750 100644
--- a/src/NMS.AMQP/Provider/Amqp/AmqpConsumer.cs
+++ b/src/NMS.AMQP/Provider/Amqp/AmqpConsumer.cs
@@ -152,17 +152,10 @@ namespace Apache.NMS.AMQP.Provider.Amqp
             source.Capabilities = new[] { SymbolUtil.GetTerminusCapabilitiesForDestination(info.Destination) };
 
             Map filters = new Map();
-
-            // TODO add filters for noLocal and Selector using appropriate Amqp Described types
-
-            // No Local
-            // qpid jms defines a no local filter as an amqp described type 
-            //      AmqpJmsNoLocalType where
-            //          Descriptor = 0x0000468C00000003UL
-            //          Described = "NoLocalFilter{}" (type string)
+            
             if (info.NoLocal)
             {
-                filters.Add(SymbolUtil.ATTACH_FILTER_NO_LOCAL, "NoLocalFilter{}");
+                filters.Add(SymbolUtil.ATTACH_FILTER_NO_LOCAL, AmqpNmsNoLocalType.NO_LOCAL);
             }
 
             if (info.HasSelector)
@@ -170,7 +163,6 @@ namespace Apache.NMS.AMQP.Provider.Amqp
                 filters.Add(SymbolUtil.ATTACH_FILTER_SELECTOR, new AmqpNmsSelectorType(info.Selector));
             }
 
-            // Assign filters
             if (filters.Count > 0)
             {
                 source.FilterSet = filters;
diff --git a/src/NMS.AMQP/Provider/Amqp/Filters/AmqpNmsNoLocalType.cs b/src/NMS.AMQP/Provider/Amqp/Filters/AmqpNmsNoLocalType.cs
new file mode 100644
index 0000000..ca82dff
--- /dev/null
+++ b/src/NMS.AMQP/Provider/Amqp/Filters/AmqpNmsNoLocalType.cs
@@ -0,0 +1,35 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+using Amqp.Types;
+
+namespace Apache.NMS.AMQP.Provider.Amqp.Filters
+{
+    public class AmqpNmsNoLocalType : DescribedValue
+    {
+        private const ulong DESCRIPTOR = 0x0000468C00000003L;
+        private const string DESCRIBED = "NoLocalFilter{}";
+        
+        public static readonly AmqpNmsNoLocalType NO_LOCAL = new AmqpNmsNoLocalType();
+
+        private AmqpNmsNoLocalType() : base(DESCRIPTOR, DESCRIBED)
+        {
+        }
+
+        public override string ToString() => $"AmqpNmsSelectorType{{ {this.Value} }}";
+    }
+}
\ No newline at end of file
diff --git a/test/Apache-NMS-AMQP-Interop-Test/AmqpTestSupport.cs b/test/Apache-NMS-AMQP-Interop-Test/AmqpTestSupport.cs
index 73e49e6..2155d86 100644
--- a/test/Apache-NMS-AMQP-Interop-Test/AmqpTestSupport.cs
+++ b/test/Apache-NMS-AMQP-Interop-Test/AmqpTestSupport.cs
@@ -116,5 +116,22 @@ namespace NMS.AMQP.Test
 
             amqpConnection.Close();
         }
+
+        protected void PurgeTopic(TimeSpan timeout)
+        {
+            IConnection amqpConnection = CreateAmqpConnection();
+            amqpConnection.Start();
+            ISession session = amqpConnection.CreateSession(AcknowledgementMode.AutoAcknowledge);
+            ITopic queue = session.GetTopic(TestName);
+            IMessageConsumer consumer = session.CreateConsumer(queue);
+
+            IMessage message;
+            do
+            {
+                message = consumer.Receive(timeout);
+            } while (message != null);
+
+            amqpConnection.Close();
+        }
     }
 }
\ No newline at end of file
diff --git a/test/Apache-NMS-AMQP-Interop-Test/NmsMessageConsumerTest.cs b/test/Apache-NMS-AMQP-Interop-Test/NmsMessageConsumerTest.cs
index 462b4d7..4529783 100644
--- a/test/Apache-NMS-AMQP-Interop-Test/NmsMessageConsumerTest.cs
+++ b/test/Apache-NMS-AMQP-Interop-Test/NmsMessageConsumerTest.cs
@@ -83,5 +83,22 @@ namespace NMS.AMQP.Test
             Assert.AreEqual(text, ((ITextMessage) msg).Text);
             Assert.IsNull(messageConsumer.Receive(TimeSpan.FromSeconds(1)));
         }
+
+        [Test, Timeout(60_000)]
+        public void TestSelectNoLocal()
+        {
+            PurgeTopic(TimeSpan.FromMilliseconds(500));
+            
+            Connection = CreateAmqpConnection();
+            Connection.Start();
+            
+            ISession session = Connection.CreateSession(AcknowledgementMode.AutoAcknowledge);
+            ITopic topic = session.GetTopic(TestName);
+            IMessageProducer producer = session.CreateProducer(topic);                        
+            ITextMessage message = session.CreateTextMessage("text");
+            producer.Send(message, MsgDeliveryMode.Persistent, MsgPriority.Normal, TimeSpan.Zero);
+            IMessageConsumer messageConsumer = session.CreateConsumer(topic, null, noLocal: true);
+            Assert.IsNull(messageConsumer.Receive(TimeSpan.FromMilliseconds(500)));
+        }
     }
 }
\ No newline at end of file