[camel] branch master updated: CAMEL-13864: Allow subscriptionName to be set for non-durable shared subscription

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[camel] branch master updated: CAMEL-13864: Allow subscriptionName to be set for non-durable shared subscription

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

davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/master by this push:
     new c62b19b  CAMEL-13864: Allow subscriptionName to be set for non-durable shared subscription
c62b19b is described below

commit c62b19bcda0e51e2817dfd06aa2d6b734d276cde
Author: Benjamin Graf <[hidden email]>
AuthorDate: Tue Aug 13 21:23:42 2019 +0200

    CAMEL-13864: Allow subscriptionName to be set for non-durable shared subscription
---
 .../apache/camel/component/jms/JmsEndpoint.java    |  6 ++--
 .../jms/JmsEndpointConfigurationTest.java          | 38 ++++++++++++++++++++++
 2 files changed, 41 insertions(+), 3 deletions(-)

diff --git a/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsEndpoint.java b/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsEndpoint.java
index 4d02c57..e6c6cf7 100644
--- a/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsEndpoint.java
+++ b/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsEndpoint.java
@@ -244,9 +244,9 @@ public class JmsEndpoint extends DefaultEndpoint implements AsyncEndpoint, Heade
             listenerContainer.setDurableSubscriptionName(configuration.getDurableSubscriptionName());
         } else if (configuration.isSubscriptionDurable()) {
             listenerContainer.setSubscriptionDurable(true);
-            if (configuration.getSubscriptionName() != null) {
-                listenerContainer.setSubscriptionName(configuration.getSubscriptionName());
-            }
+        }
+        if (configuration.getSubscriptionName() != null) {
+            listenerContainer.setSubscriptionName(configuration.getSubscriptionName());
         }
         listenerContainer.setSubscriptionShared(configuration.isSubscriptionShared());
     }
diff --git a/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsEndpointConfigurationTest.java b/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsEndpointConfigurationTest.java
index 695c736..7a49e7f 100644
--- a/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsEndpointConfigurationTest.java
+++ b/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsEndpointConfigurationTest.java
@@ -70,6 +70,44 @@ public class JmsEndpointConfigurationTest extends CamelTestSupport {
     }
 
     @Test
+    public void testDurableSharedSubscriber() throws Exception {
+        JmsEndpoint endpoint = resolveMandatoryEndpoint("jms:topic:Foo.Bar?subscriptionDurable=true&subscriptionShared=true&subscriptionName=James", JmsEndpoint.class);
+        JmsConfiguration configuration = endpoint.getConfiguration();
+        assertEquals("isSubscriptionDurable()", true, configuration.isSubscriptionDurable());
+        assertEquals("isSubscriptionShared()", true, configuration.isSubscriptionShared());
+        assertEquals("getSubscriptionName()", "James", configuration.getSubscriptionName());
+
+        JmsConsumer consumer = endpoint.createConsumer(new Processor() {
+            public void process(Exchange exchange) throws Exception {
+                log.info("Received: " + exchange);
+            }
+        });
+        AbstractMessageListenerContainer listenerContainer = consumer.getListenerContainer();
+        assertEquals("isSubscriptionDurable()", true, listenerContainer.isSubscriptionDurable());
+        assertEquals("isSubscriptionShared()", true, listenerContainer.isSubscriptionShared());
+        assertEquals("getSubscriptionName()", "James", listenerContainer.getSubscriptionName());
+    }
+
+    @Test
+    public void testNonDurableSharedSubscriber() throws Exception {
+        JmsEndpoint endpoint = resolveMandatoryEndpoint("jms:topic:Foo.Bar?subscriptionShared=true&subscriptionName=James", JmsEndpoint.class);
+        JmsConfiguration configuration = endpoint.getConfiguration();
+        assertEquals("isSubscriptionDurable()", false, configuration.isSubscriptionDurable());
+        assertEquals("isSubscriptionShared()", true, configuration.isSubscriptionShared());
+        assertEquals("getSubscriptionName()", "James", configuration.getSubscriptionName());
+
+        JmsConsumer consumer = endpoint.createConsumer(new Processor() {
+            public void process(Exchange exchange) throws Exception {
+                log.info("Received: " + exchange);
+            }
+        });
+        AbstractMessageListenerContainer listenerContainer = consumer.getListenerContainer();
+        assertEquals("isSubscriptionDurable()", false, listenerContainer.isSubscriptionDurable());
+        assertEquals("isSubscriptionShared()", true, listenerContainer.isSubscriptionShared());
+        assertEquals("getSubscriptionName()", "James", listenerContainer.getSubscriptionName());
+    }
+
+    @Test
     public void testSetUsernameAndPassword() throws Exception {
         JmsEndpoint endpoint = resolveMandatoryEndpoint("jms:topic:Foo.Bar?username=James&password=ABC", JmsEndpoint.class);
         ConnectionFactory cf = endpoint.getConfiguration().getConnectionFactory();