camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r790476 - in /camel/trunk/components/camel-jms/src: main/java/org/apache/camel/component/jms/ test/java/org/apache/camel/component/jms/ test/java/org/apache/camel/component/jms/issues/ test/resources/org/apache/camel/component/jms/issues/
Date Thu, 02 Jul 2009 07:09:46 GMT
Author: davsclaus
Date: Thu Jul  2 07:09:45 2009
New Revision: 790476

URL: http://svn.apache.org/viewvc?rev=790476&view=rev
Log:
CAMEL-1783: You can now provide a header to JmsProducer with the destination name to send
to instead of the endpoint destination. Allows to reuse same endpoint sending to dynamic computed
destinations. Recucing the number of endpoints needed etc.

Added:
    camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/JmsSendToAlotOfDestinationWithSameEndpointTest.java
  (with props)
    camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/issues/broker.xml
  (with props)
    camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/issues/camelBrokerClient.xml
  (with props)
Modified:
    camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/EndpointMessageListener.java
    camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsConstants.java
    camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsProducer.java
    camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsProducerWithJMSHeaderTest.java
    camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsSimpleRequestLateReplyTest.java
    camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsSimpleRequestReply102Test.java
    camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsSimpleRequestReplyTest.java
    camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/JmsCustomJMSReplyToIssueTest.java

Modified: camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/EndpointMessageListener.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/EndpointMessageListener.java?rev=790476&r1=790475&r2=790476&view=diff
==============================================================================
--- camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/EndpointMessageListener.java
(original)
+++ camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/EndpointMessageListener.java
Thu Jul  2 07:09:45 2009
@@ -142,7 +142,6 @@
 
         // lets set to an InOut if we have some kind of reply-to destination
         if (replyDestination != null && !disableReplyTo) {
-            exchange.setProperty(JmsConstants.JMS_REPLY_DESTINATION, replyDestination);
             // only change pattern if not already out capable
             if (!exchange.getPattern().isOutCapable()) {
                 exchange.setPattern(ExchangePattern.InOut);

Modified: camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsConstants.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsConstants.java?rev=790476&r1=790475&r2=790476&view=diff
==============================================================================
--- camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsConstants.java
(original)
+++ camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsConstants.java
Thu Jul  2 07:09:45 2009
@@ -21,12 +21,10 @@
  */
 public final class JmsConstants {
 
-    public static final String JMS_REPLY_DESTINATION = "JMSReplyTo";
-
-    public static final String JMS_DESTINATION = "JMSDestination";
-
+    public static final String JMS_DESTINATION = "CamelJmsDestination";
+    public static final String JMS_DESTINATION_NAME = "CamelJmsDestinationName";
     public static final String JMS_MESSAGE_TYPE = "CamelJmsMessageType";
-    public static final String JMS_DELIVERY_MODE = "CamelJMSDeliveryMode";
+    public static final String JMS_DELIVERY_MODE = "CamelJmsDeliveryMode";
 
     private JmsConstants() {
         // utility class

Modified: camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsProducer.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsProducer.java?rev=790476&r1=790475&r2=790476&view=diff
==============================================================================
--- camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsProducer.java
(original)
+++ camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsProducer.java
Thu Jul  2 07:09:45 2009
@@ -154,8 +154,16 @@
     protected void processInOut(final Exchange exchange) {
         final org.apache.camel.Message in = exchange.getIn();
 
-        String destinationName = endpoint.getDestinationName();
-        Destination destination = exchange.getProperty(JmsConstants.JMS_DESTINATION, Destination.class);
+        String destinationName = in.getHeader(JmsConstants.JMS_DESTINATION_NAME, String.class);
+        // remove the header so it wont be propagated
+        in.removeHeader(JmsConstants.JMS_DESTINATION_NAME);
+        if (destinationName == null) {
+            destinationName = endpoint.getDestinationName();
+        }
+
+        Destination destination = in.getHeader(JmsConstants.JMS_DESTINATION, Destination.class);
+        // remove the header so it wont be propagated
+        in.removeHeader(JmsConstants.JMS_DESTINATION);
         if (destination == null) {
             destination = endpoint.getDestination();
         }
@@ -262,8 +270,16 @@
     protected void processInOnly(final Exchange exchange) {
         final org.apache.camel.Message in = exchange.getIn();
 
-        String destinationName = endpoint.getDestinationName();
-        Destination destination = exchange.getProperty(JmsConstants.JMS_DESTINATION, Destination.class);
+        String destinationName = in.getHeader(JmsConstants.JMS_DESTINATION_NAME, String.class);
+        // remove the header so it wont be propagated
+        in.removeHeader(JmsConstants.JMS_DESTINATION_NAME);
+        if (destinationName == null) {
+            destinationName = endpoint.getDestinationName();
+        }
+
+        Destination destination = in.getHeader(JmsConstants.JMS_DESTINATION, Destination.class);
+        // remove the header so it wont be propagated
+        in.removeHeader(JmsConstants.JMS_DESTINATION);
         if (destination == null) {
             destination = endpoint.getDestination();
         }

Modified: camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsProducerWithJMSHeaderTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsProducerWithJMSHeaderTest.java?rev=790476&r1=790475&r2=790476&view=diff
==============================================================================
--- camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsProducerWithJMSHeaderTest.java
(original)
+++ camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsProducerWithJMSHeaderTest.java
Thu Jul  2 07:09:45 2009
@@ -199,13 +199,25 @@
     @Test
     public void testInOnlyJMSDestination() throws Exception {
         Destination queue = new ActiveMQQueue("foo");
-        
+
+        MockEndpoint mock = getMockEndpoint("mock:result");
+        mock.expectedMessageCount(1);
+        mock.message(0).header("JMSDestination").isNotNull();
+
+        template.sendBodyAndHeader("activemq:queue:bar", "Hello World", JmsConstants.JMS_DESTINATION,
queue);
+
+        assertMockEndpointsSatisfied();
+
+        assertEquals("queue://foo", mock.getReceivedExchanges().get(0).getIn().getHeader("JMSDestination",
Destination.class).toString());
+    }
+
+    @Test
+    public void testInOnlyJMSDestinationName() throws Exception {
         MockEndpoint mock = getMockEndpoint("mock:result");
         mock.expectedMessageCount(1);
         mock.message(0).header("JMSDestination").isNotNull();
 
-        // must use a property for JMSDestination to send it somewhere else
-        template.sendBodyAndProperty("activemq:queue:bar", "Hello World", "JMSDestination",
queue);
+        template.sendBodyAndHeader("activemq:queue:bar", "Hello World", JmsConstants.JMS_DESTINATION_NAME,
"foo");
 
         assertMockEndpointsSatisfied();
 

Modified: camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsSimpleRequestLateReplyTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsSimpleRequestLateReplyTest.java?rev=790476&r1=790475&r2=790476&view=diff
==============================================================================
--- camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsSimpleRequestLateReplyTest.java
(original)
+++ camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsSimpleRequestLateReplyTest.java
Thu Jul  2 07:09:45 2009
@@ -105,10 +105,10 @@
             template.send("activemq:dummy", new Processor() {
                 public void process(Exchange exchange) throws Exception {
                     exchange.setPattern(ExchangePattern.InOnly);
-                    exchange.setProperty(JmsConstants.JMS_DESTINATION, replyDestination);
-                    
+
                     Message in = exchange.getIn();
                     in.setBody(expectedBody);
+                    in.setHeader(JmsConstants.JMS_DESTINATION, replyDestination);
                     in.setHeader("JMSCorrelationID", cid);
                 }
             });
@@ -170,7 +170,7 @@
                         Message in = exchange.getIn();
                         assertEquals("Hello World", in.getBody());
 
-                        replyDestination = in.getHeader(JmsConstants.JMS_REPLY_DESTINATION,
Destination.class);
+                        replyDestination = in.getHeader("JMSReplyTo", Destination.class);
                         cid = in.getHeader("JMSCorrelationID", String.class);
 
                         LOG.debug("ReplyDestination: " + replyDestination);

Modified: camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsSimpleRequestReply102Test.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsSimpleRequestReply102Test.java?rev=790476&r1=790475&r2=790476&view=diff
==============================================================================
--- camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsSimpleRequestReply102Test.java
(original)
+++ camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsSimpleRequestReply102Test.java
Thu Jul  2 07:09:45 2009
@@ -71,8 +71,7 @@
                 from("activemq:queue:hello?useVersion102=true").process(new Processor() {
                     public void process(Exchange exchange) throws Exception {
                         exchange.getIn().setBody("Bye World");
-                        // the reply destination is set as a property on the exchange while
we process it
-                        assertNotNull(exchange.getProperty(JmsConstants.JMS_REPLY_DESTINATION));
+                        assertNotNull(exchange.getIn().getHeader("JMSReplyTo"));
                     }
                 }).to("mock:result");
             }

Modified: camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsSimpleRequestReplyTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsSimpleRequestReplyTest.java?rev=790476&r1=790475&r2=790476&view=diff
==============================================================================
--- camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsSimpleRequestReplyTest.java
(original)
+++ camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsSimpleRequestReplyTest.java
Thu Jul  2 07:09:45 2009
@@ -71,8 +71,7 @@
                 from("activemq:queue:hello").process(new Processor() {
                     public void process(Exchange exchange) throws Exception {
                         exchange.getIn().setBody("Bye World");
-                        // the reply destination is set as a property on the exchange while
we process it
-                        assertNotNull(exchange.getProperty(JmsConstants.JMS_REPLY_DESTINATION));
+                        assertNotNull(exchange.getIn().getHeader("JMSReplyTo"));
                     }
                 }).to("mock:result");
             }

Modified: camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/JmsCustomJMSReplyToIssueTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/JmsCustomJMSReplyToIssueTest.java?rev=790476&r1=790475&r2=790476&view=diff
==============================================================================
--- camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/JmsCustomJMSReplyToIssueTest.java
(original)
+++ camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/JmsCustomJMSReplyToIssueTest.java
Thu Jul  2 07:09:45 2009
@@ -25,7 +25,6 @@
 import org.apache.camel.Exchange;
 import org.apache.camel.Processor;
 import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.component.jms.JmsConstants;
 import org.apache.camel.component.mock.MockEndpoint;
 import org.springframework.jms.core.JmsTemplate;
 import static org.apache.activemq.camel.component.ActiveMQComponent.activeMQComponent;
@@ -75,8 +74,8 @@
                 from("direct:start").process(new Processor() {
                     public void process(Exchange exchange) throws Exception {
                         exchange.getOut().setBody("Hello World");
-                        // use our custom JMSReplyTo to decide where the reply should be
sent
-                        exchange.getOut().setHeader(JmsConstants.JMS_REPLY_DESTINATION, "myReplyQueue");
+                        // set the JMSReplyTo to force sending the reply here
+                        exchange.getOut().setHeader("JMSReplyTo", "myReplyQueue");
                     }
                 // must preserve QoS so Camel will send JMSReplyTo even if message is inOnly
                 }).to("activemq:queue:in?preserveMessageQos=true");

Added: camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/JmsSendToAlotOfDestinationWithSameEndpointTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/JmsSendToAlotOfDestinationWithSameEndpointTest.java?rev=790476&view=auto
==============================================================================
--- camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/JmsSendToAlotOfDestinationWithSameEndpointTest.java
(added)
+++ camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/JmsSendToAlotOfDestinationWithSameEndpointTest.java
Thu Jul  2 07:09:45 2009
@@ -0,0 +1,57 @@
+/**
+ * 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.
+ */
+package org.apache.camel.component.jms.issues;
+
+import org.apache.camel.component.jms.JmsConstants;
+import org.apache.camel.spring.SpringTestSupport;
+import org.apache.xbean.spring.context.ClassPathXmlApplicationContext;
+import org.junit.Test;
+import org.springframework.context.support.AbstractXmlApplicationContext;
+
+/**
+ * @version $Revision$
+ */
+public class JmsSendToAlotOfDestinationWithSameEndpointTest extends SpringTestSupport {
+
+    private static String URI = "activemq:queue:foo";
+
+    public int getExpectedRouteCount() {
+        return 0;
+    }
+
+    @Test
+    public void testSendToAlotOfMessageToQueues() throws Exception {
+        int size = 100;
+
+        for (int i = 0; i < size; i++) {
+            // use the same endpoint but provide a header with the dynamic queue we send
to
+            // this allows us to reuse endpoints and not create a new endpoint for each and
every jms queue
+            // we send to
+            template.sendBodyAndHeader(URI, "Hello " + i, JmsConstants.JMS_DESTINATION_NAME,
"foo" + i);
+        }
+
+        // now we should be able to poll a message from each queue
+//        System.out.println(size + " messages sent, use jconsole to look");
+//        Thread.sleep(99999999);
+    }
+
+    protected AbstractXmlApplicationContext createApplicationContext() {
+        return new ClassPathXmlApplicationContext(new String[]{"classpath:org/apache/camel/component/jms/issues/broker.xml",
+                "classpath:org/apache/camel/component/jms/issues/camelBrokerClient.xml"});
+    }
+
+}

Propchange: camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/JmsSendToAlotOfDestinationWithSameEndpointTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/JmsSendToAlotOfDestinationWithSameEndpointTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/issues/broker.xml
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/issues/broker.xml?rev=790476&view=auto
==============================================================================
--- camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/issues/broker.xml
(added)
+++ camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/issues/broker.xml
Thu Jul  2 07:09:45 2009
@@ -0,0 +1,47 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<beans xmlns="http://www.springframework.org/schema/beans"
+       xmlns:amq="http://activemq.apache.org/schema/core"
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xsi:schemaLocation="
+		http://www.springframework.org/schema/beans
+			http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
+		http://activemq.apache.org/schema/core
+			http://activemq.apache.org/schema/core/activemq-core-5.3-SNAPSHOT.xsd
+	">
+
+    <amq:broker brokerName="myBroker"
+                id="broker"
+                useJmx="true"
+                persistent="true"
+                start="true"
+                dataDirectory="target/data">
+
+        <amq:destinationPolicy>
+            <amq:policyMap>
+                <amq:policyEntries>
+                    <amq:policyEntry queue=">"
+                                     minimumMessageSize="1"
+                                     optimizedDispatch="true"
+                                     lazyDispatch="false"
+                                     producerFlowControl="false"
+                                     memoryLimit="500 kb"
+                                     strictOrderDispatch="true">
+                        <amq:dispatchPolicy>
+                            <amq:strictOrderDispatchPolicy/>
+                        </amq:dispatchPolicy>
+                        <amq:subscriptionRecoveryPolicy>
+                            <amq:timedSubscriptionRecoveryPolicy recoverDuration="360000"/>
+                        </amq:subscriptionRecoveryPolicy>
+                    </amq:policyEntry>
+                </amq:policyEntries>
+            </amq:policyMap>
+        </amq:destinationPolicy>
+
+        <amq:transportConnectors>
+            <amq:transportConnector uri="tcp://localhost:61616"/>
+        </amq:transportConnectors>
+
+    </amq:broker>
+
+</beans>

Propchange: camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/issues/broker.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/issues/broker.xml
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/issues/broker.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml

Added: camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/issues/camelBrokerClient.xml
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/issues/camelBrokerClient.xml?rev=790476&view=auto
==============================================================================
--- camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/issues/camelBrokerClient.xml
(added)
+++ camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/issues/camelBrokerClient.xml
Thu Jul  2 07:09:45 2009
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+    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.
+-->
+<beans xmlns="http://www.springframework.org/schema/beans"
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xsi:schemaLocation="
+http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
+http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
+
+    <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
+        <template id="template"/>
+    </camelContext>
+
+    <bean id="jmsConnectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory">
+        <property name="brokerURL" value="tcp://localhost:61616"/>
+    </bean>
+
+    <bean id="jmsConfig" class="org.apache.camel.component.jms.JmsConfiguration">
+        <property name="connectionFactory" ref="jmsConnectionFactory"/>
+        <property name="transacted" value="false"/>
+        <property name="concurrentConsumers" value="10"/>
+    </bean>
+
+    <bean id="activemq" class="org.apache.activemq.camel.component.ActiveMQComponent">
+        <property name="configuration" ref="jmsConfig"/>
+    </bean>
+
+</beans>

Propchange: camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/issues/camelBrokerClient.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/issues/camelBrokerClient.xml
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/issues/camelBrokerClient.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml



Mime
View raw message