Loan Broker Example
This example shows how to use Camel to implement the EIP's loan broker example.
The example has two versions, one is queue version which leverages the message queue to combinate the credit agency and bank loan quote processing and it uses the InOnly exchage pattern; the other is web service version which shows how to integrate the credit agency and bank web services together and it uses the InOut exchange pattern.
Implementation with message queue (JMS)
The queue version of loan broker is based on the camel-jms component, and it shows how to using the message queue to connect the different service models (such as the credit agency , and banks).
The example should run if you type
mvn exec:java -PQueue.LoanBroker mvn exec:java -PQueue.Client
To stop the example hit ctrl + c
let's take a look how this service modules are put together.
The CreditAgency , Bank and Translator are all the implementation of Processor interface. We implement the business logicals in the void process(Exchange exchange) method.
CreditAgency
Bank
Translator
You may found we set a custom aggregation strategy to find out the lowest loan rate from bank response message.
We start the loan broker after we start up the ActiveMq broker and the connection factory of Camel-JMS component.
Now we can send the request from client
Here is how we pull the response message
Implementation with web service
The web service version of loan broker is based on the camel-cxf component which can produce and consume the SOAP message on the wire. It uses the InOut Message exchange pattern, when the client send out the message to the router , it can get the response message back from the same endpoint.
When we send out the quote message to the three different banks, we could choice to call the bank service one by one or send out the message parallelly(one request thread per request).
You can compare the response time after you run the sample.
The example should run if you type
mvn exec:java -PWS.LoanBroker mvn exec:java -PWS.Client
To stop the example hit ctrl + c
First, let's go through the SEI (Service Endpoint Interface) for LoanBroker, CreditAgency and Bank.
LoanBroker
CreditAgency
Bank
Here are two routing rules in DSL , one is for routing the request to bank sequentially, the other is for calling the bank service parallely.
We use the CreditScoreProcessor to send two request to credit agency to get the credit history length and the credit score and prepare the request message for the bank.
Now we implement the Bank and CreditAgency SEI with the business logical codes.
Bank
CreditAgency
The below codes show how the start the loan broker.
We can send the request by creating a client proxy with the LoanBroker SEI in the client code. BTW, you can compare the two different routing rule's performance by running the client.