Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3

...

The example has two versions,one for JMS, one for webservice one.
The JMS version which leverages the message queue to connect the credit agency and bank loan quote processors together, it just uses the InOnly exchange pattern to handle the message asynchronously;
the webservice version which shows how to integrate the credit agency and bank web services together by using the InOut exchange pattern synchronously.

...

Example 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).

...

To stop the example hit ctrl + c

let's take a look how this service modules are put together.

Wiki Markup
{snippet:id=dsl|lang=java|url=activemq/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/queue/version/LoanBroker.java}

The CreditAgency , Bank and Translator are all the implementation of Processor interface. We implement the business logical in the void process(Exchange exchange) method.

CreditAgency

Wiki Markup
{snippet:id=creditAgency|lang=java|url=activemq/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/queue/version/CreditAgency.java}

Bank

Wiki Markup
{snippet:id=bank|lang=java|url=activemq/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/queue/version/Bank.java}

Translator

Wiki Markup
{snippet:id=translator|lang=java|url=activemq/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/queue/version/Translator.java}

You may found we set a custom aggregation strategy to find out the lowest loan rate from bank response message.

Wiki Markup
{snippet:id=aggregation|lang=java|url=activemq/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/queue/version/BankResponseAggregationStrategy.java}

We start the loan broker after we start up the ActiveMq broker and the connection factory of Camel-JMS component.

Wiki Markup
{snippet:id=starting|lang=java|url=activemq/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/queue/version/LoanBroker.java}

Now we can send the request from client and pull the response message back

Wiki Markup
{snippet:id=client|lang=java|url=activemq/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/queue/version/Client.java}

...

Example 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.

...

To stop the example hit ctrl + c

First, let's go through the SEI (Service Endpoint Interface) for LoanBroker, CreditAgency and Bank.

LoanBroker

Wiki Markup
{snippet:id=loanBroker|lang=java|url=activemq/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/webservice/version/LoanBrokerWS.java}

CreditAgency

Wiki Markup
{snippet:id=creditAgency|lang=java|url=activemq/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/webservice/version/credit/CreditAgencyWS.java}

Bank

Wiki Markup
{snippet:id=bank|lang=java|url=activemq/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/webservice/version/bank/BankWS.java}

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.

Wiki Markup
{snippet:id=dsl|lang=java|url=activemq/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/webservice/version/LoanBroker.java}

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.

Wiki Markup
{snippet:id=credit|lang=java|url=activemq/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/webservice/version/LoanBroker.java}

Now we implement the Bank and CreditAgency SEI with the business logical codes.

Bank

Wiki Markup
{snippet:id=bankImpl|lang=java|url=activemq/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/webservice/version/bank/Bank.java}

CreditAgency

Wiki Markup
{snippet:id=creditAgencyImpl|lang=java|url=activemq/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/webservice/version/credit/CreditAgency.java}

The below codes show how the start the loan broker.

Wiki Markup
{snippet:id=server|lang=java|url=activemq/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/webservice/version/LoanBroker.java}

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.

...