camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [2/2] git commit: CAMEL-4257: Allow to configure custom delivery mode. Thanks to Christian Posta for the patch.
Date Tue, 24 Sep 2013 09:50:31 GMT
CAMEL-4257: Allow to configure custom delivery mode. Thanks to Christian Posta for the patch.


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/017b47b5
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/017b47b5
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/017b47b5

Branch: refs/heads/camel-2.12.x
Commit: 017b47b52cf1842e04f1d6802bb9dbf5cc1506c1
Parents: 936a589
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Tue Sep 24 11:49:44 2013 +0200
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Tue Sep 24 11:49:59 2013 +0200

----------------------------------------------------------------------
 .../camel/component/jms/JmsComponent.java       |  4 ++
 .../camel/component/jms/JmsConfiguration.java   | 20 ++++++-
 .../apache/camel/component/jms/JmsEndpoint.java | 10 ++++
 .../JmsRouteDeliveryModePreserveQoSTest.java    | 61 +++++++++++++++++++-
 4 files changed, 91 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/017b47b5/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsComponent.java
----------------------------------------------------------------------
diff --git a/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsComponent.java
b/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsComponent.java
index 2576946..f9777ab 100644
--- a/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsComponent.java
+++ b/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsComponent.java
@@ -206,6 +206,10 @@ public class JmsComponent extends UriEndpointComponent implements ApplicationCon
         getConfiguration().setDeliveryPersistent(deliveryPersistent);
     }
 
+    public void setDeliveryMode(Integer deliveryMode) {
+        getConfiguration().setDeliveryMode(deliveryMode);
+    }
+
     public void setDurableSubscriptionName(String durableSubscriptionName) {
         getConfiguration().setDurableSubscriptionName(durableSubscriptionName);
     }

http://git-wip-us.apache.org/repos/asf/camel/blob/017b47b5/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsConfiguration.java
----------------------------------------------------------------------
diff --git a/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsConfiguration.java
b/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsConfiguration.java
index 08a36e1..04c1306 100644
--- a/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsConfiguration.java
+++ b/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsConfiguration.java
@@ -119,6 +119,8 @@ public class JmsConfiguration implements Cloneable {
     @UriParam
     private boolean deliveryPersistent = true;
     @UriParam
+    private Integer deliveryMode;
+    @UriParam
     private boolean replyToDeliveryPersistent = true;
     @UriParam
     private long timeToLive = -1;
@@ -396,7 +398,14 @@ public class JmsConfiguration implements Cloneable {
         template.setDefaultDestinationName(destination);
 
         template.setExplicitQosEnabled(isExplicitQosEnabled());
-        template.setDeliveryPersistent(deliveryPersistent);
+
+        // have to use one or the other.. doesn't make sense to use both
+        if (deliveryMode != null) {
+            template.setDeliveryMode(deliveryMode);
+        } else {
+            template.setDeliveryPersistent(deliveryPersistent);
+        }
+
         if (messageConverter != null) {
             template.setMessageConverter(messageConverter);
         }
@@ -742,6 +751,15 @@ public class JmsConfiguration implements Cloneable {
         configuredQoS();
     }
 
+    public Integer getDeliveryMode() {
+        return deliveryMode;
+    }
+
+    public void setDeliveryMode(Integer deliveryMode) {
+        this.deliveryMode = deliveryMode;
+        configuredQoS();
+    }
+
     public boolean isReplyToDeliveryPersistent() {
         return replyToDeliveryPersistent;
     }

http://git-wip-us.apache.org/repos/asf/camel/blob/017b47b5/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsEndpoint.java
----------------------------------------------------------------------
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 a8110af..4f5ea57 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
@@ -663,6 +663,11 @@ public class JmsEndpoint extends DefaultEndpoint implements HeaderFilterStrategy
     }
 
     @ManagedAttribute
+    public Integer getDeliveryMode() {
+        return getConfiguration().getDeliveryMode();
+    }
+
+    @ManagedAttribute
     public boolean isDisableReplyTo() {
         return getConfiguration().isDisableReplyTo();
     }
@@ -793,6 +798,11 @@ public class JmsEndpoint extends DefaultEndpoint implements HeaderFilterStrategy
         getConfiguration().setDeliveryPersistent(deliveryPersistent);
     }
 
+    @ManagedAttribute
+    public void setDeliveryMode(Integer deliveryMode) {
+        getConfiguration().setDeliveryMode(deliveryMode);
+    }
+
     public void setDestinationResolver(DestinationResolver destinationResolver) {
         getConfiguration().setDestinationResolver(destinationResolver);
     }

http://git-wip-us.apache.org/repos/asf/camel/blob/017b47b5/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsRouteDeliveryModePreserveQoSTest.java
----------------------------------------------------------------------
diff --git a/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsRouteDeliveryModePreserveQoSTest.java
b/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsRouteDeliveryModePreserveQoSTest.java
index 6598f41..8c651c2 100644
--- a/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsRouteDeliveryModePreserveQoSTest.java
+++ b/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsRouteDeliveryModePreserveQoSTest.java
@@ -24,7 +24,6 @@ import org.apache.camel.CamelContext;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mock.MockEndpoint;
 import org.apache.camel.test.junit4.CamelTestSupport;
-
 import org.junit.Test;
 
 import static org.apache.camel.component.jms.JmsComponent.jmsComponentAutoAcknowledge;
@@ -109,10 +108,62 @@ public class JmsRouteDeliveryModePreserveQoSTest extends CamelTestSupport
{
         assertEquals(DeliveryMode.PERSISTENT, map.get("JMSDeliveryMode"));
     }
 
+    @Test
+    public void testNonJmsDeliveryMode() throws InterruptedException {
+        MockEndpoint mock = getMockEndpoint("mock:bar");
+        mock.expectedBodiesReceived("Beer is good...");
+
+        // since we're using activemq, we really cannot set a delivery mode to something
other
+        // than 1 or 2 (NON-PERSISTENT or PERSISTENT, respectively). but this test does try
to
+        // set the delivery mode to '3'... so ActiveMQ will just test to see whether it's
persistent
+        // by testing deliverMode == 2 ... but it won't be... so it will evaluate to NON-PERSISTENT..
+        // so our test asserts the deliveryMode was changed to 1 (NON-PERSISTENT), as 2 (PERSISTENT)
is the default.
+        // we would need an in memory broker that does allow non-jms delivery modes to really
+        // test this right....
+        mock.message(0).header("JMSDeliveryMode").isEqualTo(1);
+
+        template.sendBody("direct:nonJmsDeliveryMode", "Beer is good...");
+
+        assertMockEndpointsSatisfied();
+    }
+
+    @Test
+    public void testNonJmsDeliveryModeDisableExplicityQos() throws InterruptedException {
+        MockEndpoint mock = getMockEndpoint("mock:bar");
+        mock.expectedBodiesReceived("Beer is good...");
+
+        // in this test, we're using explicitQosEnabled=false so we will not rely on our
+        // settings, we will rely on whatever is created in the Message creator, which
+        // should default to default message QoS, namely, PERSISTENT deliveryMode
+        mock.message(0).header("JMSDeliveryMode").isEqualTo(2);
+
+        template.sendBody("direct:noExplicitNonJmsDeliveryMode", "Beer is good...");
+
+        assertMockEndpointsSatisfied();
+    }
+
+    @Test
+    public void testNonJmsDeliveryModePreserveQos() throws InterruptedException {
+        MockEndpoint mock = getMockEndpoint("mock:bar");
+        mock.expectedBodiesReceived("Beer is good...");
+
+        // in this test, we can only pass if we are "preserving" existing deliveryMode.
+        // this means camel expects to have an existing QoS set as a header, or it will pick
+        // from the JMS message created by the message creator
+        // otherwise, "preserveMessageQos==true" does not allow us to explicity set the deliveryMode
+        // on the message
+        mock.message(0).header("JMSDeliveryMode").isEqualTo(1);
+
+        template.sendBodyAndHeader("direct:preserveQosNonJmsDeliveryMode", "Beer is good...",
JmsConstants.JMS_DELIVERY_MODE, 3);
+
+        assertMockEndpointsSatisfied();
+    }
+
     protected CamelContext createCamelContext() throws Exception {
         CamelContext camelContext = super.createCamelContext();
 
         ConnectionFactory connectionFactory = CamelJmsTestHelper.createPersistentConnectionFactory();
+
         camelContext.addComponent("activemq", jmsComponentAutoAcknowledge(connectionFactory));
 
         return camelContext;
@@ -124,10 +175,14 @@ public class JmsRouteDeliveryModePreserveQoSTest extends CamelTestSupport
{
             @Override
             public void configure() throws Exception {
                 from("activemq:queue:foo")
-                    .to("activemq:queue:bar?preserveMessageQos=true");
+                        .to("activemq:queue:bar?preserveMessageQos=true");
 
                 from("activemq:queue:bar")
-                    .to("mock:bar");
+                        .to("mock:bar");
+
+                from("direct:nonJmsDeliveryMode").to("activemq:queue:bar?deliveryMode=3");
+                from("direct:noExplicitNonJmsDeliveryMode").to("activemq:queue:bar?deliveryMode=3&explicitQosEnabled=false");
+                from("direct:preserveQosNonJmsDeliveryMode").to("activemq:queue:bar?preserveMessageQos=true");
             }
         };
     }


Mime
View raw message