camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jans...@apache.org
Subject svn commit: r740056 - in /camel/trunk: camel-core/src/test/java/org/apache/camel/processor/ components/camel-spring/src/test/java/org/apache/camel/spring/processor/scattergather/ components/camel-spring/src/test/resources/org/apache/camel/spring/proces...
Date Mon, 02 Feb 2009 18:17:14 GMT
Author: janstey
Date: Mon Feb  2 18:17:13 2009
New Revision: 740056

URL: http://svn.apache.org/viewvc?rev=740056&view=rev
Log:
CAMEL-1173 - Add a better example of scatter-gather

Added:
    camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/scattergather/
    camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/scattergather/LowestQuoteAggregationStrategy.java
  (with props)
    camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/scattergather/MyVendor.java
  (with props)
    camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/scattergather/ScatterGatherTest.java
  (with props)
    camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/scattergather/
    camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/scattergather/scatter-gather.xml
  (with props)
Removed:
    camel/trunk/camel-core/src/test/java/org/apache/camel/processor/ScatterGatherTest.java

Added: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/scattergather/LowestQuoteAggregationStrategy.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/scattergather/LowestQuoteAggregationStrategy.java?rev=740056&view=auto
==============================================================================
--- camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/scattergather/LowestQuoteAggregationStrategy.java
(added)
+++ camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/scattergather/LowestQuoteAggregationStrategy.java
Mon Feb  2 18:17:13 2009
@@ -0,0 +1,30 @@
+/**
+ * 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.spring.processor.scattergather;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.processor.aggregate.AggregationStrategy;
+
+public class LowestQuoteAggregationStrategy implements AggregationStrategy {
+    public Exchange aggregate(Exchange oldExchange, Exchange newExchange) {
+        if (oldExchange.getIn().getBody(int.class) < newExchange.getIn().getBody(int.class))
{
+            return oldExchange;
+        } else {
+            return newExchange;
+        }
+    }
+}
\ No newline at end of file

Propchange: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/scattergather/LowestQuoteAggregationStrategy.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/scattergather/MyVendor.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/scattergather/MyVendor.java?rev=740056&view=auto
==============================================================================
--- camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/scattergather/MyVendor.java
(added)
+++ camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/scattergather/MyVendor.java
Mon Feb  2 18:17:13 2009
@@ -0,0 +1,42 @@
+/**
+ * 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.spring.processor.scattergather;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Produce;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.language.XPath;
+
+public class MyVendor {
+    private int beerPrice;
+    
+    @Produce(uri = "seda:quoteAggregator")
+    private ProducerTemplate quoteAggregator;
+            
+    public MyVendor(int beerPrice) {
+        this.beerPrice = beerPrice;
+    }
+        
+    public void getQuote(@XPath("/quote_request/@item") String item, Exchange exchange) throws
Exception {
+        if ("beer".equals(item)) {
+            exchange.getIn().setBody(beerPrice);
+            quoteAggregator.send(exchange);
+        } else {
+            throw new Exception("No quote available for " + item);
+        }
+    }
+}
\ No newline at end of file

Propchange: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/scattergather/MyVendor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/scattergather/ScatterGatherTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/scattergather/ScatterGatherTest.java?rev=740056&view=auto
==============================================================================
--- camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/scattergather/ScatterGatherTest.java
(added)
+++ camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/scattergather/ScatterGatherTest.java
Mon Feb  2 18:17:13 2009
@@ -0,0 +1,46 @@
+/**
+ * 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.spring.processor.scattergather;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.component.mock.MockEndpoint;
+
+import static org.apache.camel.spring.processor.SpringTestHelper.createSpringCamelContext;
+
+public class ScatterGatherTest extends ContextTestSupport {
+
+    public void testScatterAndGather() throws Exception {
+        MockEndpoint result = getMockEndpoint("mock:result");
+        result.expectedMessageCount(1);
+        result.expectedBodiesReceived(1); // expect the lowest quote
+        
+        Map<String, Object> headers = new HashMap<String, Object>();
+        headers.put("listOfVendors", "bean:vendor1, bean:vendor2, bean:vendor3");
+        headers.put("quoteRequestId", "quoteRequest-1");
+        template.sendBodyAndHeaders("direct:start", "<quote_request item=\"beer\"/>",
headers);
+        
+        result.assertIsSatisfied();
+    }
+    
+    protected CamelContext createCamelContext() throws Exception {
+        return createSpringCamelContext(this, "org/apache/camel/spring/processor/scattergather/scatter-gather.xml");
+    }
+}

Propchange: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/scattergather/ScatterGatherTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/scattergather/scatter-gather.xml
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/scattergather/scatter-gather.xml?rev=740056&view=auto
==============================================================================
--- camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/scattergather/scatter-gather.xml
(added)
+++ camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/scattergather/scatter-gather.xml
Mon Feb  2 18:17:13 2009
@@ -0,0 +1,64 @@
+<?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://activemq.apache.org/camel/schema/spring http://activemq.apache.org/camel/schema/spring/camel-spring.xsd
+    ">
+
+  <!-- START SNIPPET: example -->
+  <camelContext id="camel" xmlns="http://activemq.apache.org/camel/schema/spring">
+    <route>
+      <from uri="direct:start"/>
+      <recipientList>
+        <header>listOfVendors</header>
+      </recipientList>
+    </route>
+    <route>
+      <from uri="seda:quoteAggregator"/>
+      <aggregate strategyRef="aggregatorStrategy">
+        <correlationExpression>
+          <header>quoteRequestId</header>
+        </correlationExpression>
+        <to uri="mock:result"/>
+      </aggregate>
+    </route>
+  </camelContext>
+
+  <bean id="aggregatorStrategy" class="org.apache.camel.spring.processor.scattergather.LowestQuoteAggregationStrategy"/>
+
+  <bean id="vendor1" class="org.apache.camel.spring.processor.scattergather.MyVendor">
+    <constructor-arg>
+      <value>1</value>
+    </constructor-arg>
+  </bean>
+
+  <bean id="vendor2" class="org.apache.camel.spring.processor.scattergather.MyVendor">
+    <constructor-arg>
+      <value>2</value>
+    </constructor-arg>
+  </bean>
+
+  <bean id="vendor3" class="org.apache.camel.spring.processor.scattergather.MyVendor">
+    <constructor-arg>
+      <value>3</value>
+    </constructor-arg>
+  </bean>
+  <!-- END SNIPPET: example -->
+</beans>

Propchange: camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/scattergather/scatter-gather.xml
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message