<?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.
    -->
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
           xmlns:ext="http://aries.apache.org/blueprint/xmlns/blueprint-ext/v1.0.0">

  <camelContext xmlns="http://camel.apache.org/schema/blueprint" id="LoanBroker">

    <!-- the banks -->
    <endpoint id="Bank1" uri="activemq:LoanBroker.Bank1"/>
    <endpoint id="Bank2" uri="activemq:LoanBroker.Bank2"/>
    <endpoint id="Bank3" uri="activemq:LoanBroker.Bank3"/>

    <route id="LoanRequests">
      <from uri="timer://LoanRequests?fixedRate=true&amp;period=5000"/>
      <removeHeader headerName="firedTime"/>
      <setExchangePattern pattern="InOut"/>
      <to uri="activemq:LoanBroker.LoanBrokerService"/>
    </route>

    <route id="LoanBroker">
      <from uri="activemq:LoanBroker.LoanBrokerService"/>
      <setHeader headerName="host.loan.broker">
        <simple>${sys.runtime.id}</simple>
      </setHeader>
      <to uri="activemq:LoanBroker.CreditBureauService"/>
      <log message="&gt;&gt;&gt; Credit score : ${header.credit.score}"/>
      <to uri="activemq:LoanBroker.RuleBaseService"/>
      <log message="&gt;&gt;&gt; Bank list : ${header.bank.list}"/>
      <!-- call the banks and pick the winning bank with the best rate -->
      <recipientList parallelProcessing="false">
        <header>bank.list</header>
      </recipientList>
      <log message="&gt;&gt;&gt; Loan rate : ${header.loan.rate} , from bank : ${header.host.bank}"/>
    </route>

    <route id="CreditBureau">
      <from uri="activemq:LoanBroker.CreditBureauService"/>
      <setHeader headerName="host.credit.bureau">
        <simple>${sys.runtime.id}</simple>
      </setHeader>
      <delay>
        <constant>100</constant>
      </delay>
      <setHeader headerName="credit.score">
        <simple>7</simple>
      </setHeader>
    </route>

    <route id="RuleBase">
      <from uri="activemq:LoanBroker.RuleBaseService"/>
      <setHeader headerName="host.rule.base">
        <simple>${sys.runtime.id}</simple>
      </setHeader>
      <delay>
        <constant>50</constant>
      </delay>
      <setHeader headerName="bank.list">
        <simple>Bank1,Bank2,Bank3</simple>
      </setHeader>
    </route>
  </camelContext>

  <bean id="activemq" class="org.apache.activemq.camel.component.ActiveMQComponent">
    <property name="brokerURL" value="tcp://localhost:61616"/>
    <property name="userName" value="karaf"/>
    <property name="password" value="karaf"/>
  </bean>

</blueprint>
