Some reader favorites:
EJB fundamentals and session beans
Create a scrollable virtual desktop in Swing
Web services test code generator
Klaus Berg has recently released a test-code generator for JUnit-based Web service clients. If you're developing Web services
using Axis2 and XMLBeans this wizard could turn your JUnit test client coding into a powerful code generation process. It
also has uses for those using GUI-based testing tools like soapUI.
| Memory Analysis in Eclipse |
| Enterprise AJAX - Transcend the Hype |
The Java Business Integration specification (JBI) defines a standard for building system integration applications using Web Services Description Language (WSDL) and XML-based messaging. JBI therefore aims to standardize the business-to-business integration space that was, until JBI, served by non-standardized products. Now, clients can use a JBI-compliant enterprise service bus (ESB) built by a vendor as a bundle of services that can integrate seamlessly with other services (even if developed by other vendors), as long as they adhere to the JBI specification—an impossibility before the JBI.
In this article, we look at how component-to-component interactions happen in a JBI-compliant way over an ESB, using the Loan Broker example bundled with the open source ESB ServiceMix.
The primary focus of the JBI specification is to define standards in the following areas:
JBI introduces the concept of a normalized message router (NMR), which is the backbone of all communication that happens within the ESB. As per the JBI-defined architecture, the ESB can be viewed as a conglomeration of distributed services that interact with each other to provide services to external clients. The JBI also defines a set of message exchange patterns (MEPs) based on which services (provided through components) can communicate with each other over the NMR.
In this article, we look at how the In-Out MEP is used in ServiceMix's Loan Broker example to let components communicate with each other over the NMR.
Figure 1 is an excerpt from the JBI Specification regarding the In-Out MEP.
Figure 1. In-Out MEP (as shown in the JBI Specification). Click on thumbnail to view full-sized image.
As shown in Figure 1:
Each message exchange sequence therefore has components playing the role of either consumer or producer:
The Loan Broker example is an ESB implementation for the use-case described in Enterprise Integration Patterns. I suggest you read and understand the use-case as stated in this book before going forward with this article.
Here is the abstract of the use-case:
The source for the Loan Broker example can be found in the [service mix install directory]\examples\loan-broker folder. The source of the Loan Broker example comes with two servicemix.xml files. The servicemix.xml file under the service mix install directory is used to start ServiceMix without any components, service, or default service units.
The other servicemix.xml file can be found under the [loan broker install directory]\examples\loan-broker\src\su folder. This file is used to install components at runtime. All components discussed later are installed based on the configurations specified in this servicemix.xml file.
The example uses the following business components, the source of which can be found under the examples in [loan broker install directory]\loan-broker\src\components\loanbroker:
LoanBroker: This component serves as a hub for all the communication that happens with other components. It receives the client-supplied
message from the source queue through the binding component (JmsServiceComponent). This is the component that implements the business logic to derive the best possible quote for the client. It interfaces
with other components and provides the result to the client.
CreditAgency: A transformation component that provides credit agency rating information based on the request from the LoanBroker.
LenderGateway: A transformation component that provides as a response the list of banks that can be considered for loan processing.
Bank: Transformation component that provides the rate of interest for the loan.
Other than these components, there is a ServiceMix-provided Java Message Service component, JmsServiceComponent, that is used to interface with the source and destination message queues.
Figure 2 shows all the interactions that happen in the process of implementing the use-case. Each interaction is abstracted in the JBI-specified message exchange object, and each of these message exchanges is explained in the following sections.

Figure 2. Message exchanges in loan broker
The use-case begins with the client (JmsClient.java) adding a message for a loan request into the source (demo.org.servicemix.source) queue.
The following component-to-component interactions happen in the process of returning a loan quote:
JmsServiceComponent interaction
JmsServiceComponent-to-LoanBroker interaction
LoanBroker-to-CreditAgency interaction
LoanBroker-to-LenderGateway interaction
LoanBroker-to-Bank interaction
LoanBroker-to-JmsServiceComponent interaction
JmsServiceComponent-to-client interaction
I now discuss each of these interactions to illustrate the roles played by the components:
JmsServiceComponent:
JmsServiceComponent listens to the source queue and picks up the message that was added by the client.
JMSServiceComponent to pick up messages from the source queue: <sm: component>
<bean class="org.apache.servicemix.components.jms.JmsServiceComponent">
<property name="template">
<bean class="org.springframework.jms.core.JmsTemplate">
<property name="connectionFactory" ref="jmsFactory" />
<property name="defaultDestinationName" value="demo.org.servicemix.source" />
<property name="pubSubDomain" value="false" />
</bean>
</property>
</bean>
</sm: component>
JmsServiceComponent to LoanBroker component:
JmsServiceComponent is the consumer and the LoanBroker is the provider.
JmsServiceComponent creates an instance of MessageExchange and sends the message to the LoanBroker component based on the configuration of the servicemix.xml file.
LoanBroker's onMessageExchange() method is invoked when the component receives the message sent by the JmsServiceComponent over the NMR.
processInputRequest() method is invoked. Here is what happens in this method:Aggregation object is created using the Social Security Number (SSN), amount, and duration as specified in the client request message.
LoanBroker is stored as a reference in the Aggregation object.
InOutExchange object is created with a destination provider component set as a CreditAgency component. Here is the code excerpt of the LoanBroker.java used to create the InOutExchange object: InOut inout = createInOutExchange(new QName(Constants.LOANBROKER_NS,
Constants.CREDITAGENCY_SERVICE), null, null);
CreditAgency component as described below.
LoanBroker to CreditAgency:LoanBroker plays the role of a consumer and the CreditAgency plays the role of a producer.
LoanBroker completes the following processing before sending out the message:CreditAgency's transform() method is invoked when the component receives the message from the NMR.
CreditAgency sets the credit rating information as properties in the "out" message.
LoanBroker).
LoanBroker over the NMR, processCreditAgencyResponse() is called.
LoanBroker extracts the credit information from the messageExchange and saves it in the Aggregation object.
LoanBroker and CreditAgency is set to "done," the message between the LoanBroker component and LenderGateway begins as described below.
LoanBroker to LenderGateway:LoanBroker is the consumer and the LenderGateway is the provider.
processCreditAgencyResponse() is called to process the "out" message received from the CreditAgency.
LenderGateway.
LoanBroker to CreditAgency exchange, the credit rating information received from the credit agency along with other information, such as correlation
ID, is added to the MessageExchange as properties.
LenderGateway, and the message is sent over the NMR using the send method.
LenderGateway receives the message over the NMR and the transform() method is invoked.
LenderGateway sets the list of short-listed banks as a part of the "out" message:
(out.setProperty(Constants.PROPERTY_RECIPIENTS, recipients);)
LoanBroker) when the transform() method returns.
LoanBroker receives the "out" message when the onMessageExchange() method is invoked, which then invokes the processLenderGatewayResponse() method.
LoanBroker extracts the list of recipient banks from the "out" message.
LoanBroker then ends this message exchange sequence by calling the done() method on the message exchange, thus setting the status to "done."
LoanBroker now interfaces with the banks as described below.
LoanBroker to Bank:LoanBroker is that of a consumer and Bank is that of a provider.
processLenderGatewayResponse() is invoked by LoanBroker to process the "out" message.
Bank.java) in servicemix.xml.
Bank component over the NMR.
Bank component receives the "in" message from the NMR and sets the rate in the "out" message as a property.
LoanBroker receives the "out" message and invokes the processLoanQuote() method.
done() method is called.
LoanBroker to JmsServiceComponent:LoanBroker decides the best quote for the client: ( for (Iterator iter = ag.quotes.iterator(); iter.hasNext();) {
q = (LoanQuote) iter.next();
if (best == null || q.rate.doubleValue() <> best = q;
}
})
LoanBroker sets the bank quote as a property in the message created by the JmsServiceComponent.
LoanBroker sends the "out" message over the NMR by calling send() on MessageExchange.
JmsServiceComponent receives the "out" message and ends the message exchange by setting the status to "complete."
JmsServiceComponent to Client:JmsServiceComponent adds the result to the output demo.org.servicemix.output queue.
The Loan Broker example shows us how multiple components interact with each other in a distributed manner to provide services. The pluggable component nature of a JBI-compliant ESB has enabled us to implement business logic as a set of distributed components that communicate with each other using message exchanges.
The In-Out message exchange is used to implement two-way communication between components, as specified by the JBI specification.
In this article, we have seen how business information is communicated between components using the properties of the MessageExchange object. The JBI specification also specifies three other message exchange patterns: In-Only, Robust In-Only, and In-Optional-Out.
Each of these patterns has usage scenarios based on the reliability requirements of the message exchange. The role of consumer
and producer components also varies based on the MEP chosen for communication.
| Subject | Replies |
Last post
|
|
By mikegeorge12 |
0 |
12/10/07 12:51 AM
by mikegeorge12 |
|
By JavaWorld |
0 |
11/21/06 03:01 AM
by Anonymous |
|
By |
0 |
11/06/06 08:13 AM
by Anonymous |