<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE mule-configuration PUBLIC "-//MuleSource //DTD mule-configuration XML V1.0//EN"
                                "http://mule.mulesource.org/dtds/mule-configuration.dtd">

<!--
This loan broker example is modeled on the Enterprise integration Patterns book
sample.
This implementation differs in that this configuration uses an asynchronous
model where each component communicates messaging accordin to it's configuration
in this file.
There is a synchronous version of this in the loan-broker-sync-config.xml where calls to
the different components are made from the loan broker component (a la hub and spoke).
-->

<mule-configuration id="Loan_broker_Async" version="1.0">

    <mule-environment-properties>
        <threading-profile maxThreadsActive="20" maxThreadsIdle="20" maxBufferSize="500" poolExhaustedAction="WAIT"/>
        <pooling-profile exhaustedAction="WHEN_EXHAUSTED_GROW" maxActive="20" maxIdle="20" maxWait="-1" initialisationPolicy="INITIALISE_ALL" />
        <queue-profile maxOutstandingMessages="5000"/>
    </mule-environment-properties>

    <agents>
        <agent name="JmxAgent" className="org.mule.management.agents.JmxAgent"/>
        <agent name="JdmkAgent" className="org.mule.management.agents.JdmkAgent"/>
    </agents>

    <!--
    Setting global endpoints can help simplify configuration by defining an actual
    url endpointUri in one place. The endpointUri name can be used in place of the url.
    -->
    <endpoint-identifiers>
        <endpoint-identifier name="LoanBrokerRequests" value="vm://LoanBrokerRequests"/>
        <endpoint-identifier name="LoanBrokerQuotes" value="vm://LoanBrokerQuotes"/>
        <endpoint-identifier name="CreditAgency" value="vm://CreditAgencyService"/>
        <endpoint-identifier name="CreditAgencyReceiver" value="vm://CreditAgencyService"/>
        <endpoint-identifier name="LenderService" value="vm://LenderService"/>
        <endpoint-identifier name="Bank1" value="vm://Bank1"/>
        <endpoint-identifier name="Bank2" value="vm://Bank2"/>
        <endpoint-identifier name="Bank3" value="vm://Bank3"/>
        <endpoint-identifier name="Bank4" value="vm://Bank4"/>
        <endpoint-identifier name="Bank5" value="vm://Bank5"/>
    </endpoint-identifiers>

     <!--
       The Mule model initialises and manages your UMO components
   -->
    <model name="loan-broker">
        <!-- by declaring the Axis service component we can overload its default
        configuration to add more threads or pooled resources -->
        <mule-descriptor name="_axisServiceComponent"
            implementation="org.mule.transport.soap.axis.AxisServiceComponent">
            <threading-profile maxBufferSize="100" threadTTL="600000" maxThreadsActive="30" maxThreadsIdle="20"/>
            <pooling-profile exhaustedAction="WAIT" maxActive="20" maxIdle="20" maxWait="20000"/>
        </mule-descriptor>
        <!--
        The loan broker is used to receive loan requests
        -->
        <mule-descriptor name="LoanBroker"
                         implementation="org.mule.example.loanbroker.AsyncLoanBroker">

            <!--
            This router uses the BankQuoteAggregator for events of type BankQuote, for all other
            types the catch all strategy is invoked, which simply passes the event to the component
            -->
            <inbound-router>
                <catch-all-strategy className="org.mule.routing.ServiceCatchAllStrategy"/>
                <endpoint address="LoanBrokerRequests"/>
                <endpoint address="LoanBrokerQuotes"/>
                <router className="org.mule.example.loanbroker.routers.BankQuotesAggregator">
                    <filter expectedType="org.mule.example.loanbroker.LoanQuote"
                            className="org.mule.routing.filters.PayloadTypeFilter"/>
                </router>
            </inbound-router>
            <outbound-router>
                <router className="org.mule.routing.outbound.OutboundPassThroughRouter">
                    <endpoint address="CreditAgency"/>
                </router>
            </outbound-router>
        </mule-descriptor>

        <!--
        The credit agency service will get the credit profile for a customer
        -->
        <mule-descriptor name="CreditAgencyService"
                         implementation="org.mule.example.loanbroker.DefaultCreditAgencyService">
            <inbound-router>
                <endpoint address="CreditAgencyReceiver"/>
            </inbound-router>
            <outbound-router>
                <router className="org.mule.routing.outbound.OutboundPassThroughRouter">
                    <endpoint address="LenderService"/>
                </router>
            </outbound-router>
        </mule-descriptor>

        <!--
        The Lender service is used to determine which banks to contact for a quote
        -->
        <mule-descriptor name="LenderService"
                         implementation="org.mule.example.loanbroker.DefaultLenderService">
            <inbound-router>
                <endpoint address="LenderService"/>
            </inbound-router>
            <!--
            this router will send an outbound event to none or more recipients which
            are set as a property on the event itelf.  A replyTo property is also set
            which tells the recipients of the event where to send the resulting event
            -->
            <outbound-router>
                <catch-all-strategy className="org.mule.routing.LoggingCatchAllStrategy"/>
                <router className="org.mule.routing.outbound.StaticRecipientList">
                    <reply-to address="LoanBrokerQuotes"/>
                </router>
            </outbound-router>
        </mule-descriptor>

        <!--
        These are mock bank services that represent remote bank loan services
        One or more of these are selected by the LenderService and a request
        is routed to them.   The lenderService outbound router also defines a
        replyTo property which will be used by Mule to route the responses back
        to the LoanBrokerQuotes destination
        -->
        <mule-descriptor name="Bank1" implementation="org.mule.example.loanbroker.Bank">
            <inbound-router>
                <endpoint address="Bank1"/>
            </inbound-router>
        </mule-descriptor>

        <mule-descriptor name="Bank2" implementation="org.mule.example.loanbroker.Bank">
            <inbound-router>
                <endpoint address="Bank2"/>
            </inbound-router>
        </mule-descriptor>

        <mule-descriptor name="Bank3" implementation="org.mule.example.loanbroker.Bank">
            <inbound-router>
                <endpoint address="Bank3"/>
            </inbound-router>
        </mule-descriptor>

        <mule-descriptor name="Bank4" implementation="org.mule.example.loanbroker.Bank">
            <inbound-router>
                <endpoint address="Bank4"/>
            </inbound-router>
        </mule-descriptor>

        <mule-descriptor name="Bank5" implementation="org.mule.example.loanbroker.Bank">
            <inbound-router>
                <endpoint address="Bank5"/>
            </inbound-router>
        </mule-descriptor>
    </model>
</mule-configuration>
