You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ni...@apache.org on 2008/05/29 10:11:37 UTC

svn commit: r661249 - in /activemq/camel/trunk/examples: ./ camel-example-loan-broker/ camel-example-loan-broker/src/ camel-example-loan-broker/src/data/ camel-example-loan-broker/src/main/ camel-example-loan-broker/src/main/java/ camel-example-loan-br...

Author: ningjiang
Date: Thu May 29 01:11:36 2008
New Revision: 661249

URL: http://svn.apache.org/viewvc?rev=661249&view=rev
Log:
CAMEL-555 Added the loan broker queue version

Added:
    activemq/camel/trunk/examples/camel-example-loan-broker/   (with props)
    activemq/camel/trunk/examples/camel-example-loan-broker/pom.xml   (with props)
    activemq/camel/trunk/examples/camel-example-loan-broker/src/
    activemq/camel/trunk/examples/camel-example-loan-broker/src/data/
    activemq/camel/trunk/examples/camel-example-loan-broker/src/data/message1.xml   (with props)
    activemq/camel/trunk/examples/camel-example-loan-broker/src/data/message2.xml   (with props)
    activemq/camel/trunk/examples/camel-example-loan-broker/src/main/
    activemq/camel/trunk/examples/camel-example-loan-broker/src/main/java/
    activemq/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/
    activemq/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/
    activemq/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/
    activemq/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/
    activemq/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/queue/
    activemq/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/queue/version/
    activemq/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/queue/version/Bank.java   (with props)
    activemq/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/queue/version/BankResponseAggregationStrategy.java   (with props)
    activemq/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/queue/version/Client.java   (with props)
    activemq/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/queue/version/Constants.java   (with props)
    activemq/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/queue/version/CreditAgency.java   (with props)
    activemq/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/queue/version/JmsBroker.java   (with props)
    activemq/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/queue/version/LoanBroker.java   (with props)
    activemq/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/queue/version/Translator.java   (with props)
    activemq/camel/trunk/examples/camel-example-loan-broker/src/main/resources/
    activemq/camel/trunk/examples/camel-example-loan-broker/src/main/resources/META-INF/
    activemq/camel/trunk/examples/camel-example-loan-broker/src/main/resources/log4j.properties   (with props)
Modified:
    activemq/camel/trunk/examples/pom.xml

Propchange: activemq/camel/trunk/examples/camel-example-loan-broker/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Thu May 29 01:11:36 2008
@@ -0,0 +1,7 @@
+.project
+.pmd
+.checkstyle
+.classpath
+target
+.settings
+eclipse-classes

Propchange: activemq/camel/trunk/examples/camel-example-loan-broker/
------------------------------------------------------------------------------
--- svn:igorn (added)
+++ svn:igorn Thu May 29 01:11:36 2008
@@ -0,0 +1,7 @@
+.project
+.pmd
+.checkstyle
+.classpath
+target
+.settings
+eclipse-classes

Added: activemq/camel/trunk/examples/camel-example-loan-broker/pom.xml
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/examples/camel-example-loan-broker/pom.xml?rev=661249&view=auto
==============================================================================
--- activemq/camel/trunk/examples/camel-example-loan-broker/pom.xml (added)
+++ activemq/camel/trunk/examples/camel-example-loan-broker/pom.xml Thu May 29 01:11:36 2008
@@ -0,0 +1,70 @@
+<?xml version="1.0" encoding="UTF-8"?><project>
+  <parent>
+    <artifactId>examples</artifactId>
+    <groupId>org.apache.camel</groupId>
+    <version>1.4-SNAPSHOT</version>
+  </parent>
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>org.apache.camel</groupId>
+  <artifactId>camel-example-loan-broker</artifactId>
+  <name>Camel :: Example :: Loan-Broker</name>
+  <description>An example that shows the EPI's loan broker demo</description>
+
+  <build>
+    <defaultGoal>install</defaultGoal>
+    <plugins>
+      <plugin>
+        <artifactId>maven-compiler-plugin</artifactId>
+        <configuration>
+          <source>1.5</source>
+          <target>1.5</target>
+        </configuration>
+      </plugin>
+      <!-- Allows the example to be run via 'mvn compile exec:java' -->
+      <plugin>
+        <groupId>org.codehaus.mojo</groupId>
+        <artifactId>exec-maven-plugin</artifactId>
+        <configuration>
+          <mainClass>${target.main.class}</mainClass>
+          <includePluginDependencies>false</includePluginDependencies>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+  <dependencies>
+    <dependency>
+      <groupId>org.apache.camel</groupId>
+      <artifactId>camel-core</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.camel</groupId>
+      <artifactId>camel-spring</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.camel</groupId>
+      <artifactId>camel-cxf</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.camel</groupId>
+      <artifactId>camel-jms</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.activemq</groupId>
+      <artifactId>apache-activemq</artifactId>
+    </dependency>
+  </dependencies>
+  <profiles>
+    <profile>
+        <id>Queue.LoanBroker</id>
+    	<properties>
+            <target.main.class>org.apache.camel.loanbroker.queue.version.LoanBroker</target.main.class>
+        </properties>
+    </profile>
+    <profile>
+        <id>Queue.Client</id>
+    	<properties>
+            <target.main.class>org.apache.camel.loanbroker.queue.version.Client</target.main.class>
+        </properties>
+    </profile>
+  </profiles>
+</project>
\ No newline at end of file

Propchange: activemq/camel/trunk/examples/camel-example-loan-broker/pom.xml
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: activemq/camel/trunk/examples/camel-example-loan-broker/pom.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml

Added: activemq/camel/trunk/examples/camel-example-loan-broker/src/data/message1.xml
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/examples/camel-example-loan-broker/src/data/message1.xml?rev=661249&view=auto
==============================================================================
--- activemq/camel/trunk/examples/camel-example-loan-broker/src/data/message1.xml (added)
+++ activemq/camel/trunk/examples/camel-example-loan-broker/src/data/message1.xml Thu May 29 01:11:36 2008
@@ -0,0 +1,22 @@
+<?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.
+-->
+<person user="james">
+  <firstName>James</firstName>
+  <lastName>Strachan</lastName>
+  <city>London</city>
+</person>
\ No newline at end of file

Propchange: activemq/camel/trunk/examples/camel-example-loan-broker/src/data/message1.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: activemq/camel/trunk/examples/camel-example-loan-broker/src/data/message1.xml
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: activemq/camel/trunk/examples/camel-example-loan-broker/src/data/message1.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml

Added: activemq/camel/trunk/examples/camel-example-loan-broker/src/data/message2.xml
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/examples/camel-example-loan-broker/src/data/message2.xml?rev=661249&view=auto
==============================================================================
--- activemq/camel/trunk/examples/camel-example-loan-broker/src/data/message2.xml (added)
+++ activemq/camel/trunk/examples/camel-example-loan-broker/src/data/message2.xml Thu May 29 01:11:36 2008
@@ -0,0 +1,22 @@
+<?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.
+-->
+<person user="hiram">
+  <firstName>Hiram</firstName>
+  <lastName>Chirino</lastName>
+  <city>Tampa</city>
+</person>
\ No newline at end of file

Propchange: activemq/camel/trunk/examples/camel-example-loan-broker/src/data/message2.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: activemq/camel/trunk/examples/camel-example-loan-broker/src/data/message2.xml
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: activemq/camel/trunk/examples/camel-example-loan-broker/src/data/message2.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml

Added: activemq/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/queue/version/Bank.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/queue/version/Bank.java?rev=661249&view=auto
==============================================================================
--- activemq/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/queue/version/Bank.java (added)
+++ activemq/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/queue/version/Bank.java Thu May 29 01:11:36 2008
@@ -0,0 +1,49 @@
+/**
+ * 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.loanbroker.queue.version;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+public class Bank implements Processor {
+    private static final transient Log LOG = LogFactory.getLog(Bank.class);
+    private String bankName;
+
+    public Bank(String name) {
+        bankName = name;
+    }
+
+    public void process(Exchange exchange) throws Exception {
+        LOG.info("Receiving bank request");
+        String clientId = (String)exchange.getIn().getHeader(Constants.PROPERTY_CLIENT_ID);
+        double rate = Math.random() * 10;
+        LOG.info("The bank: " + bankName + " for client: " + clientId + " 's rate " + rate);
+        exchange.getOut().setHeader(Constants.PROPERTY_RATE, new Double(rate));
+        exchange.getOut().setHeader(Constants.PROPERTY_BANK, bankName);
+        exchange.getOut().setHeader(Constants.PROPERTY_CLIENT_ID, clientId);
+        // Sleep some time
+        try {
+            Thread.sleep((int) (Math.random() * 10) * 100);
+        } catch (InterruptedException e) {
+            // Discard
+        }
+    }
+
+}

Propchange: activemq/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/queue/version/Bank.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: activemq/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/queue/version/Bank.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: activemq/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/queue/version/BankResponseAggregationStrategy.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/queue/version/BankResponseAggregationStrategy.java?rev=661249&view=auto
==============================================================================
--- activemq/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/queue/version/BankResponseAggregationStrategy.java (added)
+++ activemq/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/queue/version/BankResponseAggregationStrategy.java Thu May 29 01:11:36 2008
@@ -0,0 +1,43 @@
+/**
+ * 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.loanbroker.queue.version;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.processor.aggregate.AggregationStrategy;
+
+public class BankResponseAggregationStrategy implements AggregationStrategy {
+
+    public Exchange aggregate(Exchange oldExchange, Exchange newExchange) {
+        Integer old = (Integer) oldExchange.getProperty("aggregated");
+        Double oldRate = (Double) oldExchange.getIn().getHeader(Constants.PROPERTY_RATE);
+        Double newRate = (Double) newExchange.getIn().getHeader(Constants.PROPERTY_RATE);
+        Exchange result = null;
+        if (old == null) {
+            old = 1;
+        }
+        if (newRate >= oldRate) {
+            result = oldExchange;
+        } else {
+            result = newExchange;
+        }
+        result.setProperty("aggregated", old + 1);
+        // copy the bank response together
+        return result;
+
+    }
+
+}

Propchange: activemq/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/queue/version/BankResponseAggregationStrategy.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: activemq/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/queue/version/BankResponseAggregationStrategy.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: activemq/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/queue/version/Client.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/queue/version/Client.java?rev=661249&view=auto
==============================================================================
--- activemq/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/queue/version/Client.java (added)
+++ activemq/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/queue/version/Client.java Thu May 29 01:11:36 2008
@@ -0,0 +1,70 @@
+/**
+ * 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.loanbroker.queue.version;
+
+import javax.jms.ConnectionFactory;
+
+import org.apache.activemq.ActiveMQConnectionFactory;
+import org.apache.camel.CamelContext;
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.jms.JmsComponent;
+import org.apache.camel.impl.CamelTemplate;
+import org.apache.camel.impl.DefaultCamelContext;
+
+public class Client extends RouteBuilder {
+
+    public static void main(String args[]) throws Exception {
+        CamelContext context = new DefaultCamelContext();
+        // Set up the ActiveMQ JMS Components
+        ConnectionFactory connectionFactory = new ActiveMQConnectionFactory("tcp://localhost:61616");
+        // Note we can explicit name of the component
+        context.addComponent("test-jms", JmsComponent.jmsComponentAutoAcknowledge(connectionFactory));
+
+        context.addRoutes(new Client());
+
+        CamelTemplate template = new CamelTemplate(context);
+
+        context.start();
+        for (int i = 0; i < 2; i++) {
+            template.sendBodyAndHeader("test-jms:queue:loanRequestQueue",
+                                       "Quote for the lowerst rate of loaning bank",
+                                       Constants.PROPERTY_CLIENT_ID, "Client" + i);
+        }
+        // Start the loan broker
+        Thread.sleep(1000 * 60);
+        context.stop();
+
+    }
+
+    /**
+     * Lets configure the Camel routing rules using Java code...
+     */
+    public void configure() {
+        from("test-jms:queue:loanReply").process(new Processor() {
+
+            public void process(Exchange exchange) throws Exception {
+                // Print out the message
+                System.out.println(exchange.getIn().getBody());
+
+            }
+
+        });
+    }
+
+}

Propchange: activemq/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/queue/version/Client.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: activemq/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/queue/version/Client.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: activemq/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/queue/version/Constants.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/queue/version/Constants.java?rev=661249&view=auto
==============================================================================
--- activemq/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/queue/version/Constants.java (added)
+++ activemq/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/queue/version/Constants.java Thu May 29 01:11:36 2008
@@ -0,0 +1,38 @@
+/**
+ * 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.loanbroker.queue.version;
+
+public interface Constants {
+
+    String LOANBROKER_NS = "http://servicemix.org/demos/loan-broker";
+
+    String LOANBROKER_SERVICE = "loan-broker";
+    String CREDITAGENCY_SERVICE = "credit-agency";
+    String LENDERGATEWAY_SERVICE = "lender-gateway";
+
+
+    String PROPERTY_SSN = "ssn";
+    String PROPERTY_AMOUNT = "amount";
+    String PROPERTY_DURATION = "duration";
+    String PROPERTY_SCORE = "score";
+    String PROPERTY_HISTORYLENGTH = "hlength";
+    String PROPERTY_RECIPIENTS = "recipients";
+    String PROPERTY_CLIENT_ID = "client_Id";
+    String PROPERTY_RATE = "rate";
+    String PROPERTY_BANK = "bank";
+
+}

Propchange: activemq/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/queue/version/Constants.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: activemq/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/queue/version/Constants.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: activemq/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/queue/version/CreditAgency.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/queue/version/CreditAgency.java?rev=661249&view=auto
==============================================================================
--- activemq/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/queue/version/CreditAgency.java (added)
+++ activemq/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/queue/version/CreditAgency.java Thu May 29 01:11:36 2008
@@ -0,0 +1,37 @@
+/**
+ * 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.loanbroker.queue.version;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+public class CreditAgency implements Processor {
+    private static final transient Log LOG = LogFactory.getLog(CreditAgency.class);
+
+    public void process(Exchange exchange) throws Exception {
+        LOG.info("Receiving credit agency request");
+        String clientId = (String)exchange.getIn().getHeader(Constants.PROPERTY_CLIENT_ID);
+        int score = (int) (Math.random() * 600 + 300);
+        int hlength = (int) (Math.random() * 19 + 1);
+        exchange.getOut().setHeader(Constants.PROPERTY_SCORE, new Integer(score));
+        exchange.getOut().setHeader(Constants.PROPERTY_HISTORYLENGTH, new Integer(hlength));
+        exchange.getOut().setHeader(Constants.PROPERTY_CLIENT_ID, clientId);
+    }
+
+}

Propchange: activemq/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/queue/version/CreditAgency.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: activemq/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/queue/version/CreditAgency.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: activemq/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/queue/version/JmsBroker.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/queue/version/JmsBroker.java?rev=661249&view=auto
==============================================================================
--- activemq/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/queue/version/JmsBroker.java (added)
+++ activemq/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/queue/version/JmsBroker.java Thu May 29 01:11:36 2008
@@ -0,0 +1,102 @@
+/**
+ * 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.loanbroker.queue.version;
+
+import java.io.File;
+
+import org.apache.activemq.broker.BrokerService;
+import org.apache.activemq.store.memory.MemoryPersistenceAdapter;
+
+public final class JmsBroker {
+    JMSEmbeddedBroker jmsBrokerThread;
+    String jmsBrokerUrl = "tcp://localhost:61616";
+    String activeMQStorageDir;
+    public JmsBroker() {
+    }
+
+    public JmsBroker(String url) {
+        jmsBrokerUrl = url;
+    }
+    
+    public void start() throws Exception {
+        jmsBrokerThread = new JMSEmbeddedBroker(jmsBrokerUrl);
+        jmsBrokerThread.startBroker();
+    }
+    
+    public void stop() throws Exception {
+        synchronized (this) {
+            jmsBrokerThread.shutdownBroker = true;
+        }
+        if (jmsBrokerThread != null) {
+            jmsBrokerThread.join();
+        }
+        
+        jmsBrokerThread = null;
+    }
+    
+    class JMSEmbeddedBroker extends Thread {
+        boolean shutdownBroker;
+        final String brokerUrl;
+        Exception exception;
+        
+        
+        public JMSEmbeddedBroker(String url) {
+            brokerUrl = url;
+        }
+        
+        public void startBroker() throws Exception {
+            synchronized (this) {
+                super.start();
+                try {
+                    wait();
+                    if (exception != null) {
+                        throw exception;
+                    }
+                } catch (InterruptedException ex) {
+                    ex.printStackTrace();
+                }
+            }
+        }
+        
+        public void run() {
+            try {  
+                //ContainerWapper container;
+                BrokerService broker = new BrokerService();
+                synchronized (this) {                                     
+                    broker.setPersistenceAdapter(new MemoryPersistenceAdapter());                    
+                    broker.setTmpDataDirectory(new File("./target"));
+                    broker.addConnector(brokerUrl);
+                    broker.start();
+                    Thread.sleep(200);
+                    notifyAll();
+                }
+                synchronized (this) {
+                    while (!shutdownBroker) {
+                        wait(1000);
+                    }
+                }                
+                broker.stop();              
+                broker = null;                
+            } catch (Exception e) {
+                exception = e;
+                e.printStackTrace();
+            }
+        }
+    }
+}
+

Propchange: activemq/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/queue/version/JmsBroker.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: activemq/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/queue/version/JmsBroker.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: activemq/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/queue/version/LoanBroker.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/queue/version/LoanBroker.java?rev=661249&view=auto
==============================================================================
--- activemq/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/queue/version/LoanBroker.java (added)
+++ activemq/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/queue/version/LoanBroker.java Thu May 29 01:11:36 2008
@@ -0,0 +1,80 @@
+/**
+ * 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.loanbroker.queue.version;
+
+
+import javax.jms.ConnectionFactory;
+
+import org.apache.activemq.ActiveMQConnectionFactory;
+import org.apache.camel.CamelContext;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.jms.JmsComponent;
+import org.apache.camel.impl.DefaultCamelContext;
+import org.apache.camel.processor.aggregate.UseLatestAggregationStrategy;
+import org.apache.camel.spring.Main;
+
+
+
+/**
+ * The LoanBroker is a RouteBuilder which builds the whole loan message routing rules
+ *
+ * @version $
+ */
+public class LoanBroker extends RouteBuilder {
+
+    /**
+     * A main() so we can easily run these routing rules in our IDE
+     * @throws Exception
+     */
+    public static void main(String... args) throws Exception {
+        CamelContext context = new DefaultCamelContext();
+        JmsBroker broker = new JmsBroker();
+        broker.start();
+        // Set up the ActiveMQ JMS Components
+        ConnectionFactory connectionFactory = new ActiveMQConnectionFactory("tcp://localhost:61616");
+        // Note we can explicity name the component
+        context.addComponent("test-jms", JmsComponent.jmsComponentAutoAcknowledge(connectionFactory));
+
+        context.addRoutes(new LoanBroker());
+        context.start();
+
+        // Start the loan broker
+        Thread.sleep(5 * 60 * 1000);
+        context.stop();
+        Thread.sleep(1000);
+        broker.stop();
+
+
+    }
+
+    /**
+     * Lets configure the Camel routing rules using Java code...
+     */
+    public void configure() {
+
+        from("test-jms:queue:loanRequestQueue").to("test-jms:queue:creditRequestQueue");
+        from("test-jms:queue:creditRequestQueue").process(new CreditAgency()).to("test-jms:queue:creditResponseQueue");
+        from("test-jms:queue:creditResponseQueue").multicast().to("test-jms:queue:bank1", "test-jms:queue:bank2", "test-jms:queue:bank3");
+        from("test-jms:queue:bank1").process(new Bank("bank1")).to("test-jms:queue:bankReplyQueue");
+        from("test-jms:queue:bank2").process(new Bank("bank2")).to("test-jms:queue:bankReplyQueue");
+        from("test-jms:queue:bank3").process(new Bank("bank3")).to("test-jms:queue:bankReplyQueue");
+        from("test-jms:queue:bankReplyQueue").aggregator(header(Constants.PROPERTY_CLIENT_ID), new BankResponseAggregationStrategy())
+            .completedPredicate(header("aggregated").isEqualTo(3)).process(new Translator()).to("test-jms:queue:loanReply");
+
+
+    }
+}

Propchange: activemq/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/queue/version/LoanBroker.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: activemq/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/queue/version/LoanBroker.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: activemq/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/queue/version/Translator.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/queue/version/Translator.java?rev=661249&view=auto
==============================================================================
--- activemq/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/queue/version/Translator.java (added)
+++ activemq/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/queue/version/Translator.java Thu May 29 01:11:36 2008
@@ -0,0 +1,32 @@
+/**
+ * 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.loanbroker.queue.version;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+
+public class Translator implements Processor {
+
+    public void process(Exchange exchange) throws Exception {
+        String bank = (String)exchange.getIn().getHeader(Constants.PROPERTY_BANK);
+        Double rate = (Double)exchange.getIn().getHeader(Constants.PROPERTY_RATE);
+        String clientId = (String)exchange.getIn().getHeader(Constants.PROPERTY_CLIENT_ID);
+        exchange.getOut().setBody("Loan quotion for Client " + clientId
+                                  + "The lowest rate of bank is " + bank + ", the rate is " + rate);
+    }
+
+}

Propchange: activemq/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/queue/version/Translator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: activemq/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/queue/version/Translator.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: activemq/camel/trunk/examples/camel-example-loan-broker/src/main/resources/log4j.properties
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/examples/camel-example-loan-broker/src/main/resources/log4j.properties?rev=661249&view=auto
==============================================================================
--- activemq/camel/trunk/examples/camel-example-loan-broker/src/main/resources/log4j.properties (added)
+++ activemq/camel/trunk/examples/camel-example-loan-broker/src/main/resources/log4j.properties Thu May 29 01:11:36 2008
@@ -0,0 +1,20 @@
+
+#
+# The logging properties used for eclipse testing, We want to see debug output on the console.
+#
+log4j.rootLogger=INFO, out
+
+# uncomment the following line to turn on Camel debugging
+#log4j.logger.org.apache.camel=DEBUG
+
+# uncomment the following line to turn on ActiveMQ debugging
+#log4j.logger.org.apache.activemq=DEBUG
+
+log4j.logger.org.springframework=WARN
+
+
+# CONSOLE appender not used by default
+log4j.appender.out=org.apache.log4j.ConsoleAppender
+log4j.appender.out.layout=org.apache.log4j.PatternLayout
+log4j.appender.out.layout.ConversionPattern=[%30.30t] %-30.30c{1} %-5p %m%n
+#log4j.appender.out.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - %m%n

Propchange: activemq/camel/trunk/examples/camel-example-loan-broker/src/main/resources/log4j.properties
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: activemq/camel/trunk/examples/camel-example-loan-broker/src/main/resources/log4j.properties
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: activemq/camel/trunk/examples/camel-example-loan-broker/src/main/resources/log4j.properties
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: activemq/camel/trunk/examples/pom.xml
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/examples/pom.xml?rev=661249&r1=661248&r2=661249&view=diff
==============================================================================
--- activemq/camel/trunk/examples/pom.xml (original)
+++ activemq/camel/trunk/examples/pom.xml Thu May 29 01:11:36 2008
@@ -57,6 +57,7 @@
     <module>camel-example-spring</module>
     <module>camel-example-spring-jms</module>
     <module>camel-example-spring-xquery</module>
+    <module>camel-example-loan-broker</module>
   </modules>
 
   <profiles>
@@ -90,4 +91,4 @@
     </profile>
   </profiles>
 
-</project>
+</project>
\ No newline at end of file