Implementing an ESB using Mule A Real World Example JavaZone 2005 Ross Mason [email_address]
Agenda Overview of ESB Introduction to Mule Mule and JBI Real-world Application Application Overview Systems Involved Design Considerations Event Flows Implementation with Mule Components Transports Returning the Loan Quote Fault Tolerance Scaling Summary
Introduction to ESB What is it? Enterprise Service Bus is an evolving architecture technique to integrate  incompatible business applications over a common messaging bus. Why do we need it? Many of the applications we write are in fact integration projects.  Only the most simple applications do not need to interact with other applications. Where does SOA fit in? ESB is one architecture style that abides by the rules of a Service Orientated Architecture. What is JBI? Java Business Integration (JSR:208) is an emerging standard that defines common interfaces for components and message exchanges for application integration. Does this all sound familiar? There is nothing new about integration, we've been doing it for years. So why the hype?
Properties of an ESB Loosely Coupled Event-Driven Highly Distributed Security/Authorization Abstract Endpoints Intelligent Routing Data Transformation (inbound/outbound) Reliable Messaging Multi-Protocol Message Bus Light Weight
Introduction to Mule Service container and messaging platform Supports a variety of topologies including ESB Highly Scalable; uses SEDA event model Lightweight and embeddable Transactional; Local and Distributed Fault tolerance; Exception management Secure; authentication/authorization (Using Spring/Acegi) Powerful event routing capabilities (based on EIP book) Support for over 20 messaging protocols/transports End-to-End Data Transformation Management and Monitoring using JMX BPEL Support Deployment: JAR, WAR, RAR, EAR.
Mule Topologies Enterprise Service Bus Client/Server and Hub n' Spoke Peer Network Pipeline Enterprise Service Network
Mule and JBI Is Mule a JBI container? There is a separate project called Mule JBI that is a JBI implementation that reuses the Mule service stack.  Does Mule work with JBI? You can use Mule transports, components and transformers inside any JBI container. Mule provides a couple of components that allows JBI components to subscribe and publish events to and from Mule. Do Mule and JBI compete? JBI solves a subset of messaging problems.  Mule addresses the basic need to move any kind of data (not just XML) between services in an organization Which is best for me? Mule of course!  The reason Mule integrates with other JBI engines and provides it own JBI container is that one integration solution will never satisfy all integration needs. Mule levels the playing field allowing you to pick and choose which technologies to integrate with.
Mule and JBI Differences JBI Described in terms of Service Engines (SEs) which are akin to components that execute business logic.  Binding Components (BCs) implement protocols to provide connectivity to SEs.  JBI uses a Message Exchange to manage interactions between components. Targeted a specifically at integration. Normalized Message Mule Components are POJOs, EJBs, Spring Beans, Remote objects.  The component never needs to call Mule APIs making them totally portable.  Flexible endpoint model where a component may have zero or more inbound and outbound endpoints.  Message routing is done via routers that are associated with the component. Mule is a ubiquitous messaging platform. A distributed container for wiring components.
Loan Broker A Real World Example
Shopping for Loans Customer calls different banks to find the best deal. Each bank asks customer for his or her social security number, the amount of the loan and the desired term. Each bank then investigates the customer's credit background, usually by contacting a credit agency, before it finally sends the customer a quote. Once the customer has received quotes from all banks, he or she can then select the best offer, i.e. the lowest  rate. [1]
The Loan Broker This process can be automated to allow customers to obtain the best quote on-line from a far broader range of banks, in much less time than if he or she were to obtain all the quotes one by one. Upon receiving customer request, Loan Broker: obtains the credit information for that customer from the credit agency requests quotes for the customer from banks listed with the Lender Service sends aggregate compilation of quotes to the customer for selection. [2]
Components Marshals a request from the message bus to the Lender Application. Lender Gateway Based on the customer's credit scoring, loan amount and duration, the lender service will select banks from which to request a LoanQuote. Lender Service Marshals a request between the message bus and the Credit Agency Application. Credit Agency Gateway An external service provider that provides crediting checking on customers to ensure the loan amount requested is feesible. Credit Agency Service Dispatches LoanRequests to one or more banks. Banking Gateway Receives LoanRequests (customer, SS number, loan amount, duration) and is responsible for aggregating LoanQuotes into response for the request. Loan Broker Service
Orchestration LoanBroker (Http/Rest) Receives Requests over Http from a client application, such as a web browser. Credit Agency (EJB) Is an EJB application that is managed by the Loan Broker company.  It exposes an EJB called  creditAgency  with a method  getCreditProfile . Lender Application (VM) Is a local component, a Pojo that will determine which lenders should be used.  Banks (SOAP) For simplicity of this example all banks expose the same WS interface, though it's quite feasible to configure Mule to invoke different interfaces for different banks. Gateways (JMS) Gateways marshal the requests from the message bus to external applications and services.
Design Considerations Constraints Application needs to support request/response processing model. Will get a high volume of requests. Synchronous processing will not give us enough throughput . Transports Using a JMS message bus Need to invoke services over JMS, Http/Rest, VM, and SOAP. Need to invoke services in external application containers (EJB). Expose components as Web services (Banks). Message The message on the bus is referred to as a LoanQuoteRequest.  In this example this is a Java bean but in real scenarios an XML document would  be used.
Loan Broker Design
Request Event Flow Client application makes a request sending the  LoanBroker  a  CustomerQuoteRequest  Message. LoanBroker  creates a  LoanQuoteRequest  Message. Mule sends the message to the Credit Agency Gateway via JMS The Gateway marshals the request and invokes the  CreditAgency  EJB. The component used in the  RelectionMessageBuilder  which automatically attaches the  CreditProfile  to the  LoanQuoteRequest  message. Mule sends the Message to the Lender Gateway via JMS The Gateway uses the VM transport to invoke the Lender Application. Mule sends the Message to the Banking Gateway via JMS The Banking Gateway in this example invokes the Banks using SOAP. Each of the Banks attaches a quote to the request and sends it back to the  LoanBroker  via the  ReplyTo  address provided by the Banking Gateway. The  ResponseRouter  on the Loan Broker Service receives the responses on the  ReplyTo  address. It selects the lowest quote received for the request and returns it to the client.
Loan Broker Implementation with Mule
Design With Mule
The Message Lets start by defining the LoanQuoteRequest Message.  In this example the Message is a Java bean and is the common message format on the bus.  Normally this would be XML, but Mule allows us to pass any data format around. public class LoanQuoteRequest implements Serializable { /** The request contains Customer info and loan amount and duration*/ private  CustomerQuoteRequest  customerRequest; /** credit profile for the customer */ private  CreditProfile  creditProfile; /** A list of lenders for this request */ private  Bank[]  lenders; /** A loan quote from a bank */ private  LoanQuote  loanQuote; ....... }
Client Request The whole chain of events is initiated with a client request.  This is done over Http using Mule's REST support. It is described in the Endpoint address – jetty:rest://localhost:8080/loanbroker Here we're saying - Embed a Jetty Servlet Engine Use the Rest servlet for receiving requests Listen on localhost:8080 Bind the Rest servlet to the context /loanbroker The request from the client would look like – http://localhost:8080/loanbroker/?name=Ross+Mason&ssn=1234& loanAmount=10000&loanDuration=24
The Message The Loan Broker endpoint receives the request as a set of Http parameters, but we need to transform this into a  CustomerQuoteRequest  object before the Loan Broker component receives it. We do this by configuring a custom transformer on the endpoint.  public Object  transform (Object src, UMOEventContext context)  throws TransformerException { String name = context.getStringProperty(" name "); int ssn = context.getIntProperty(" ssn "); double amount = context.getDoubleProperty(" loanAmount "); double duration = context.getDoubleProperty(" loanDuration "); Customer customer = new Customer(name, ssn); CustomerQuoteRequest  request =  new  CustomerQuoteRequest (customer, amount, duration); return request; }
Loan Broker Service The Loanbroker service actually doesn't need to do anything but trigger the  LoanQuoteRequest  on the bus.  Mule handles all routing transformation and passing the quote back to the callee.  The transformer configured on the REST inbound endpoint for the LoanBroker  converts the REST parameters into a  CustomerQuoteRequest  object. public class LoanBroker { public LoanQuoteRequest requestLoanQuote( CustomerQuoteRequest  request) throws Exception { LoanQuoteRequest  bqr = new  LoanQuoteRequest (); bqr.setCustomerRequest(request); return bqr; } }
Loan Broker Configuration All the detail is in the Loan Broker configuration. <mule-descriptor name=&quot;LoanBroker&quot; implementation=&quot;org.mule.samples.loanbroker.esb.LoanBroker&quot;> <inbound-router> <endpoint address=&quot; jetty:rest://localhost:8080/loanbroker &quot;/> </inbound-router> <outbound-router> <router className=&quot;org.mule.routing.outbound.OutboundPassThroughRouter&quot;> <endpoint address=&quot; jms://esb.credit.agency &quot;/> </router> </outbound-router> <response-router timeout=&quot;10000&quot;> <endpoint address=&quot; jms://esb.loan.quotes &quot;/> <router className=&quot; org.mule.samples.loanbroker.esb.routers. BankQuotesResponseAggregator &quot;/> </response-router> </mule-descriptor>
Credit Agency Gateway The Credit Agency code is even easier! We use a standard Mule Component called a  ReflectionMessageBuilder  which builds a message based on a set of results from endpoint invocations.  It will use reflection to determine how to set the result of the last endpoint invocation as a property on the master message. There are other  MessageBuilder  components such as the  ScriptMessageBuilder  component which is a JSR-223 (Scripting) component that allows you to manipulate the payload after each request using Groovy, JavaScript, Rhino or any other supported scripting language.
Credit Agency Configuration <mule-descriptor name=&quot;CreditAgencyGateway&quot; implementation=&quot;org.mule.components.builder.ReflectionMessageBuilder&quot;> <inbound-router> <endpoint address=&quot; jms://credit.agency &quot;/> </inbound-router> <outbound-router> <router className=&quot;org.mule.routing.outbound.FilteringRouter&quot;> <endpoint address=&quot; ejb://localhost:1099/local/CreditAgency?method=getCreditProfile “  transformers=“ LoanQuoteRequestToCreditProfileArgs ” responseTransformers=&quot; CreditProfileXmlToCreditProfile “ />  <properties> <list name=&quot; methodArgumentTypes &quot;> <entry value=&quot;java.lang.String&quot;/> <entry value=&quot;java.lang.String&quot;/> </list> </properties> </endpoint> <endpoint address=&quot; jms://esb.lender.service &quot;/> </router> </outbound-router> </mule-descriptor>
Credit Agency Configuration We invoke the CreditAgency application using an EJB endpoint – ejb://localhost:1099/local/CreditAgency?method=getCreditProfile This endpoint tells Mule to – Look up an EJB object at  localhost:1099 Use the JNDI name  local/CreditAgency Invoke the method  getCreditProfile  on the EJB object Notice also the  transformers  and  responseTransformers  attibutes on the endpoint.  These tell Mule how to marshal for the Application. LoanQuoteRequestToCreditProfileArgs  – Extracts the method arguments from the request as an array used to invoke  getCreditProfile . CreditProfileXmlToCreditProfile   – Parses the response Xml and creates a  CreditProfile  object that will be set on the  LoanQuoteRequest .
Lender Gateway Lender Service The Lender Agency is a Mule component, that receives events directly using the VM transport.  Leander Gateway The Lender Gateway marshals requests from the bus to the lender service.
Lender Gateway Configuration Lender Service <mule-descriptor name=&quot;LenderService&quot; implementation=&quot;org.mule.samples.loanbroker.esb.LenderService&quot;> <inbound-router> <endpoint address=&quot;vm://lender.service&quot;/> </inbound-router> </mule-descriptor> Lender Gatway <mule-descriptor name=&quot;LenderGateway”  implementation=&quot;org.mule.components.simple.BridgeComponent&quot;> <inbound-router> <endpoint address=&quot;jms://esb.lender.service&quot;/> </inbound-router> <outbound-router> <router className=&quot;org.mule.routing.outbound.ChainingRouter&quot;> <endpoint address=&quot;vm://lender.service&quot;/> <endpoint address=&quot;jms://esb.banks&quot;/> </router> </outbound-router> </mule-descriptor>
Banking Gateway The Banking Gateway is responsible for distributing requests to a list of lenders.  The  ReciptientList  router configured on  this gateway is responsible for extracting the endpoints from the message and invoking them. The  RecipientList  is a type of  Itinerary-based  router that extracts its itinerary as a static list from the event. <mule-descriptor name=&quot;BankingGateway&quot; implementation=&quot;org.mule.components.simple.BridgeComponent&quot;> <inbound-router> <endpoint address=&quot; jms://esb.banks &quot;/> </inbound-router> <outbound-router> <router className=&quot;org.mule.routing.outbound. StaticRecipientList &quot;> < reply-to  address=&quot; jms://esb.loan.quotes &quot;/> </router> </outbound-router> </mule-descriptor>
Banks The banks in this example are just simple beans that return a fixed interest rate and are exposed as SOAP services.  <mule-descriptor name=&quot;Bank1&quot; inboundEndpoint=&quot; axis:http://localhost:10001/services &quot; implementation=&quot;org.mule.samples.loanbroker.Bank&quot;> </mule-descriptor> Note to expose a component as an Axis service all you need to do is add an Axis endpoint!
Choosing the best Quote Once a back has a quote it passes it to Mule which will send the Quote on the  reply-to  endpoint specified by the  Banking Gateway . Looking back at the LoanBroker configuration, there is a  response-router  configured as - <response-router timeout=&quot;10000&quot;> <endpoint address=&quot; jms://esb.loan.quotes &quot;/> <router className=&quot;org.mule.samples.loanbroker.esb.routers. BankQuotesResponseAggregator &quot;/> </response-router> The  BankQuoteResponseAggregator  is responsible for picking the lowest quote. But before that happens Mule needs to make sure all responses are received for the request. This is done using message correlation managed by Mule.
Event Correlation When a event is dispatched from the Banking Gateway a correlationId and correlationGroupSize is attached to the SOAP message.  This is a function of the Recipient List router. It attaches the following information - CorrelationId  – and Id that associates all the dispatched events to the same group CorrelationGroupSize  – how many events are in the group. CorrelationSequence  – the order in which the events were dispatched.  The Response Router reads these correlation headers when events are received and correlates the events. When the event group correlation is complete the response-router invokes itself where developers can plug in custom logic.
Response Aggregation The  BankQuoteResponseAggregator  implements a single method that works out the lowest quote before passing it back to Mule to route the response back to the client. protected UMOMessage aggregateEvents(EventGroup events) throws RoutingException { . . . . List list = events.getEvents(); for (Iterator iterator = list.iterator(); iterator.hasNext();)  { event = (UMOEvent) iterator.next(); quote = (LoanQuote)event.getTransformedMessage(); logger.info(&quot;Processing quote: &quot; + quote); if (lowestQuote == null)  { lowestQuote = quote; } else if (quote.getInterestRate() < lowestQuote.getInterestRate())  { lowestQuote = quote; } } return new MuleMessage(lowestQuote, event.getProperties()); }
Transports Most Mule transports can be configured using just the endpoint address. i.e. tcp://localhost:45454 contains all the information necessary to make a TCP connection. However for JMS and EJB we need to define configuration properties for each such as Jndi information.  This is done by configuring connectors in our MuleXml.
Transport Configuration EJB Connector (OpenEJB – Local Server. See http://openejb.org) <connector name=&quot;ejbConnector&quot; className=&quot;org.mule.providers.ejb.EjbConnector&quot;> <properties> <property name=&quot;jndiInitialFactory&quot; value=&quot;org.openejb.client.LocalInitialContextFactory&quot;/> <property name=&quot;securityPolicy&quot; value=&quot;security.policy&quot;/> <map name=&quot;jndiProviderProperties&quot;> <property name=&quot;openejb.base&quot; value=&quot;.&quot;/> <property name=&quot;openejb.configuration&quot; value=&quot;../conf/openejb.conf&quot;/> </map> </properties> </connector> JMS Connector (ActiveMQ) <connector name=&quot;jmsConnector&quot; className=&quot;org.mule.providers.jms.JmsConnector&quot;> <properties> <property name=&quot;connectionFactoryJndiName&quot; value=&quot;ConnectionFactory&quot;/> <property name=&quot;jndiInitialFactory&quot; value=&quot;org.activemq.jndi.ActiveMQInitialContextFactory&quot;/> <property name=&quot;specification&quot; value=&quot;1.1&quot;/> </properties> </connector>
Fault Tolerance Exception Strategies Can be defined on components and connectors Can be defined globally of for each connector or component Can handle different exception types differently. Exception hierarchy provides all available information Event payloads can be re-routed on exception  Connection Strategies Control how connectors connect to underlying resources Allow for flexible retry policies Notifications of failed connections Consistent endpoint state maintained Can alter routing paths based on failed connections
Scaling SEDA Model Mule is SEDA-based, which is an architecture designed for high concurrency and throughput. JMS Clustering Currently Mule can use JMS clustering to distribute events to a cluster of Mule Nodes. Application Server Clustering Mule can be embedded inside a JCA container and allow the App server to manage its resources and cluster instances.  New Clustering Support The next release of Mule will provide clustering and distribution using JGroups/JBossCache. Load Balancing using Mule You can use a Mule instance to provide load-balancing over any transport.
Summary An ESB integrating a client application and 3 back office systems. Combined a number of transports including HTTP, JMS, EJB and Web Services. Easy to add in Exception handling, transactions, etc. All done through configuration. All event routing, management, transformation is handled by Mule. Very little code to write. Just domain-specific logic. A fully functional ESB in about an hour!
The Mule Project Project was founded in 2003. It was started after experiences with a large Financial ESB project. There are now 10 developers who help support it and add new features. Has an active user community. Is being used in companies such as HP, Sony, Deutche Bank and CitiBank. SymphonySoft has been started by Mule developers to help support and provide professional services to these projects.  For more information go to - http://mule.codehaus.org.
Resources EIP Book (Loan Broker Example) [1][2] http://www.eaipatterns.com/ComposedMessagingExample.html  http://www.eaipatterns.com/index.html Introduction to ESBs – Rick Robinson http://www-106.ibm.com/developerworks/xml/library/ws-esbscen/ ESB Learning Guide http://searchwebservices.techtarget.com/general/1,295582,sid26_gci1085711,00.html Introduction to SEDA – Matt Welsh http://www.eecs.harvard.edu/~mdw/papers/mdw-phdthesis.pdf  Mule User Guide  http://mule.codehaus.org/User+Guide
Slides and Code To get this Loan Broker ESB code and these slides go to - http://mule.codehaus.org/LoanBroker There are other examples too - http://mule.codehaus.org/Examples
Questions ?

More Related Content

PPT
Implementing ESB
PPT
4 150915033746-lva1-app6892
PPT
Mule execution
PPT
Mule execution
PDF
Constraint Aware Dynamic Web Service Composition for A Specific Business Requ...
PPTX
PPT
Implementing an ESB using Mule
Implementing ESB
4 150915033746-lva1-app6892
Mule execution
Mule execution
Constraint Aware Dynamic Web Service Composition for A Specific Business Requ...
Implementing an ESB using Mule

What's hot (19)

PPT
Introduction to mule esb's
 
KEY
Introduction to JMS and Message-Driven POJOs
PPT
Implementing an Esb using Mule
PDF
Concepts and Derivatives of Web Services
PPT
Mule real-world-old
 
PDF
WEB SERVICES COMPOSITION METHODS AND TECHNIQUES: A REVIEW
PDF
Web Service Composition
PPTX
Soa 24 enterprise service bus
PPTX
PDF
Exchange cas server providing exchange clients access to their mailbox part...
PPTX
Web service introduction 2
PDF
Introduction to Service Oriented Architectures, SOAP/WSDL Web Services and RE...
PDF
Integration of Web Service Stacks in an Esb
PDF
NEW APPROACH TO DEVELOP THE MESSENGER APPLICATION: FROM CLIENTSERVER DESIGN T...
PPT
Web service architecture
PDF
Wso2 2degrees-case-study
PPTX
Unit iii soa
PPT
20090213 Friday Food Croslocis
Introduction to mule esb's
 
Introduction to JMS and Message-Driven POJOs
Implementing an Esb using Mule
Concepts and Derivatives of Web Services
Mule real-world-old
 
WEB SERVICES COMPOSITION METHODS AND TECHNIQUES: A REVIEW
Web Service Composition
Soa 24 enterprise service bus
Exchange cas server providing exchange clients access to their mailbox part...
Web service introduction 2
Introduction to Service Oriented Architectures, SOAP/WSDL Web Services and RE...
Integration of Web Service Stacks in an Esb
NEW APPROACH TO DEVELOP THE MESSENGER APPLICATION: FROM CLIENTSERVER DESIGN T...
Web service architecture
Wso2 2degrees-case-study
Unit iii soa
20090213 Friday Food Croslocis
Ad

Similar to Javazone 2005-mule-real-world-old (20)

PPT
4. mule real-world-old
PPT
Mule execution
PPT
Mule execution
PPT
Mule execution
PPT
Mule execution
PPT
Mule execution
PPT
Implementation in mule esb
PPT
Development using anypointstudio
PPT
Mule Fundamentals
PPT
mule real world
PPT
Mule real-world
PPT
Mule real-world-old
PPT
Mule real world old
PDF
CV_PurnimaBalla_WCS-Consultant_7Yrs
DOCX
Web services SOAP Notes
PDF
Subscription based control system to automate management of events for robots
DOC
WCF tutorial
PDF
L0704065070
PPTX
Real world integration using mule
PDF
Meetup6 microservices for the IoT
4. mule real-world-old
Mule execution
Mule execution
Mule execution
Mule execution
Mule execution
Implementation in mule esb
Development using anypointstudio
Mule Fundamentals
mule real world
Mule real-world
Mule real-world-old
Mule real world old
CV_PurnimaBalla_WCS-Consultant_7Yrs
Web services SOAP Notes
Subscription based control system to automate management of events for robots
WCF tutorial
L0704065070
Real world integration using mule
Meetup6 microservices for the IoT
Ad

Recently uploaded (20)

PDF
Accessing-Finance-in-Jordan-MENA 2024 2025.pdf
DOCX
search engine optimization ppt fir known well about this
PDF
NewMind AI Weekly Chronicles – August ’25 Week III
PPT
Module 1.ppt Iot fundamentals and Architecture
PPTX
Internet of Everything -Basic concepts details
PDF
Developing a website for English-speaking practice to English as a foreign la...
PDF
Flame analysis and combustion estimation using large language and vision assi...
PDF
OpenACC and Open Hackathons Monthly Highlights July 2025
DOCX
Basics of Cloud Computing - Cloud Ecosystem
PDF
A proposed approach for plagiarism detection in Myanmar Unicode text
PDF
Enhancing plagiarism detection using data pre-processing and machine learning...
PDF
Produktkatalog für HOBO Datenlogger, Wetterstationen, Sensoren, Software und ...
PPTX
MicrosoftCybserSecurityReferenceArchitecture-April-2025.pptx
PDF
sbt 2.0: go big (Scala Days 2025 edition)
PPTX
AI IN MARKETING- PRESENTED BY ANWAR KABIR 1st June 2025.pptx
PPTX
GROUP4NURSINGINFORMATICSREPORT-2 PRESENTATION
PDF
Getting started with AI Agents and Multi-Agent Systems
PDF
Credit Without Borders: AI and Financial Inclusion in Bangladesh
PPTX
Build Your First AI Agent with UiPath.pptx
PDF
Consumable AI The What, Why & How for Small Teams.pdf
Accessing-Finance-in-Jordan-MENA 2024 2025.pdf
search engine optimization ppt fir known well about this
NewMind AI Weekly Chronicles – August ’25 Week III
Module 1.ppt Iot fundamentals and Architecture
Internet of Everything -Basic concepts details
Developing a website for English-speaking practice to English as a foreign la...
Flame analysis and combustion estimation using large language and vision assi...
OpenACC and Open Hackathons Monthly Highlights July 2025
Basics of Cloud Computing - Cloud Ecosystem
A proposed approach for plagiarism detection in Myanmar Unicode text
Enhancing plagiarism detection using data pre-processing and machine learning...
Produktkatalog für HOBO Datenlogger, Wetterstationen, Sensoren, Software und ...
MicrosoftCybserSecurityReferenceArchitecture-April-2025.pptx
sbt 2.0: go big (Scala Days 2025 edition)
AI IN MARKETING- PRESENTED BY ANWAR KABIR 1st June 2025.pptx
GROUP4NURSINGINFORMATICSREPORT-2 PRESENTATION
Getting started with AI Agents and Multi-Agent Systems
Credit Without Borders: AI and Financial Inclusion in Bangladesh
Build Your First AI Agent with UiPath.pptx
Consumable AI The What, Why & How for Small Teams.pdf

Javazone 2005-mule-real-world-old

  • 1. Implementing an ESB using Mule A Real World Example JavaZone 2005 Ross Mason [email_address]
  • 2. Agenda Overview of ESB Introduction to Mule Mule and JBI Real-world Application Application Overview Systems Involved Design Considerations Event Flows Implementation with Mule Components Transports Returning the Loan Quote Fault Tolerance Scaling Summary
  • 3. Introduction to ESB What is it? Enterprise Service Bus is an evolving architecture technique to integrate incompatible business applications over a common messaging bus. Why do we need it? Many of the applications we write are in fact integration projects. Only the most simple applications do not need to interact with other applications. Where does SOA fit in? ESB is one architecture style that abides by the rules of a Service Orientated Architecture. What is JBI? Java Business Integration (JSR:208) is an emerging standard that defines common interfaces for components and message exchanges for application integration. Does this all sound familiar? There is nothing new about integration, we've been doing it for years. So why the hype?
  • 4. Properties of an ESB Loosely Coupled Event-Driven Highly Distributed Security/Authorization Abstract Endpoints Intelligent Routing Data Transformation (inbound/outbound) Reliable Messaging Multi-Protocol Message Bus Light Weight
  • 5. Introduction to Mule Service container and messaging platform Supports a variety of topologies including ESB Highly Scalable; uses SEDA event model Lightweight and embeddable Transactional; Local and Distributed Fault tolerance; Exception management Secure; authentication/authorization (Using Spring/Acegi) Powerful event routing capabilities (based on EIP book) Support for over 20 messaging protocols/transports End-to-End Data Transformation Management and Monitoring using JMX BPEL Support Deployment: JAR, WAR, RAR, EAR.
  • 6. Mule Topologies Enterprise Service Bus Client/Server and Hub n' Spoke Peer Network Pipeline Enterprise Service Network
  • 7. Mule and JBI Is Mule a JBI container? There is a separate project called Mule JBI that is a JBI implementation that reuses the Mule service stack. Does Mule work with JBI? You can use Mule transports, components and transformers inside any JBI container. Mule provides a couple of components that allows JBI components to subscribe and publish events to and from Mule. Do Mule and JBI compete? JBI solves a subset of messaging problems. Mule addresses the basic need to move any kind of data (not just XML) between services in an organization Which is best for me? Mule of course! The reason Mule integrates with other JBI engines and provides it own JBI container is that one integration solution will never satisfy all integration needs. Mule levels the playing field allowing you to pick and choose which technologies to integrate with.
  • 8. Mule and JBI Differences JBI Described in terms of Service Engines (SEs) which are akin to components that execute business logic. Binding Components (BCs) implement protocols to provide connectivity to SEs. JBI uses a Message Exchange to manage interactions between components. Targeted a specifically at integration. Normalized Message Mule Components are POJOs, EJBs, Spring Beans, Remote objects. The component never needs to call Mule APIs making them totally portable. Flexible endpoint model where a component may have zero or more inbound and outbound endpoints. Message routing is done via routers that are associated with the component. Mule is a ubiquitous messaging platform. A distributed container for wiring components.
  • 9. Loan Broker A Real World Example
  • 10. Shopping for Loans Customer calls different banks to find the best deal. Each bank asks customer for his or her social security number, the amount of the loan and the desired term. Each bank then investigates the customer's credit background, usually by contacting a credit agency, before it finally sends the customer a quote. Once the customer has received quotes from all banks, he or she can then select the best offer, i.e. the lowest rate. [1]
  • 11. The Loan Broker This process can be automated to allow customers to obtain the best quote on-line from a far broader range of banks, in much less time than if he or she were to obtain all the quotes one by one. Upon receiving customer request, Loan Broker: obtains the credit information for that customer from the credit agency requests quotes for the customer from banks listed with the Lender Service sends aggregate compilation of quotes to the customer for selection. [2]
  • 12. Components Marshals a request from the message bus to the Lender Application. Lender Gateway Based on the customer's credit scoring, loan amount and duration, the lender service will select banks from which to request a LoanQuote. Lender Service Marshals a request between the message bus and the Credit Agency Application. Credit Agency Gateway An external service provider that provides crediting checking on customers to ensure the loan amount requested is feesible. Credit Agency Service Dispatches LoanRequests to one or more banks. Banking Gateway Receives LoanRequests (customer, SS number, loan amount, duration) and is responsible for aggregating LoanQuotes into response for the request. Loan Broker Service
  • 13. Orchestration LoanBroker (Http/Rest) Receives Requests over Http from a client application, such as a web browser. Credit Agency (EJB) Is an EJB application that is managed by the Loan Broker company. It exposes an EJB called creditAgency with a method getCreditProfile . Lender Application (VM) Is a local component, a Pojo that will determine which lenders should be used. Banks (SOAP) For simplicity of this example all banks expose the same WS interface, though it's quite feasible to configure Mule to invoke different interfaces for different banks. Gateways (JMS) Gateways marshal the requests from the message bus to external applications and services.
  • 14. Design Considerations Constraints Application needs to support request/response processing model. Will get a high volume of requests. Synchronous processing will not give us enough throughput . Transports Using a JMS message bus Need to invoke services over JMS, Http/Rest, VM, and SOAP. Need to invoke services in external application containers (EJB). Expose components as Web services (Banks). Message The message on the bus is referred to as a LoanQuoteRequest. In this example this is a Java bean but in real scenarios an XML document would be used.
  • 16. Request Event Flow Client application makes a request sending the LoanBroker a CustomerQuoteRequest Message. LoanBroker creates a LoanQuoteRequest Message. Mule sends the message to the Credit Agency Gateway via JMS The Gateway marshals the request and invokes the CreditAgency EJB. The component used in the RelectionMessageBuilder which automatically attaches the CreditProfile to the LoanQuoteRequest message. Mule sends the Message to the Lender Gateway via JMS The Gateway uses the VM transport to invoke the Lender Application. Mule sends the Message to the Banking Gateway via JMS The Banking Gateway in this example invokes the Banks using SOAP. Each of the Banks attaches a quote to the request and sends it back to the LoanBroker via the ReplyTo address provided by the Banking Gateway. The ResponseRouter on the Loan Broker Service receives the responses on the ReplyTo address. It selects the lowest quote received for the request and returns it to the client.
  • 19. The Message Lets start by defining the LoanQuoteRequest Message. In this example the Message is a Java bean and is the common message format on the bus. Normally this would be XML, but Mule allows us to pass any data format around. public class LoanQuoteRequest implements Serializable { /** The request contains Customer info and loan amount and duration*/ private CustomerQuoteRequest customerRequest; /** credit profile for the customer */ private CreditProfile creditProfile; /** A list of lenders for this request */ private Bank[] lenders; /** A loan quote from a bank */ private LoanQuote loanQuote; ....... }
  • 20. Client Request The whole chain of events is initiated with a client request. This is done over Http using Mule's REST support. It is described in the Endpoint address – jetty:rest://localhost:8080/loanbroker Here we're saying - Embed a Jetty Servlet Engine Use the Rest servlet for receiving requests Listen on localhost:8080 Bind the Rest servlet to the context /loanbroker The request from the client would look like – http://localhost:8080/loanbroker/?name=Ross+Mason&ssn=1234& loanAmount=10000&loanDuration=24
  • 21. The Message The Loan Broker endpoint receives the request as a set of Http parameters, but we need to transform this into a CustomerQuoteRequest object before the Loan Broker component receives it. We do this by configuring a custom transformer on the endpoint. public Object transform (Object src, UMOEventContext context) throws TransformerException { String name = context.getStringProperty(&quot; name &quot;); int ssn = context.getIntProperty(&quot; ssn &quot;); double amount = context.getDoubleProperty(&quot; loanAmount &quot;); double duration = context.getDoubleProperty(&quot; loanDuration &quot;); Customer customer = new Customer(name, ssn); CustomerQuoteRequest request = new CustomerQuoteRequest (customer, amount, duration); return request; }
  • 22. Loan Broker Service The Loanbroker service actually doesn't need to do anything but trigger the LoanQuoteRequest on the bus. Mule handles all routing transformation and passing the quote back to the callee. The transformer configured on the REST inbound endpoint for the LoanBroker converts the REST parameters into a CustomerQuoteRequest object. public class LoanBroker { public LoanQuoteRequest requestLoanQuote( CustomerQuoteRequest request) throws Exception { LoanQuoteRequest bqr = new LoanQuoteRequest (); bqr.setCustomerRequest(request); return bqr; } }
  • 23. Loan Broker Configuration All the detail is in the Loan Broker configuration. <mule-descriptor name=&quot;LoanBroker&quot; implementation=&quot;org.mule.samples.loanbroker.esb.LoanBroker&quot;> <inbound-router> <endpoint address=&quot; jetty:rest://localhost:8080/loanbroker &quot;/> </inbound-router> <outbound-router> <router className=&quot;org.mule.routing.outbound.OutboundPassThroughRouter&quot;> <endpoint address=&quot; jms://esb.credit.agency &quot;/> </router> </outbound-router> <response-router timeout=&quot;10000&quot;> <endpoint address=&quot; jms://esb.loan.quotes &quot;/> <router className=&quot; org.mule.samples.loanbroker.esb.routers. BankQuotesResponseAggregator &quot;/> </response-router> </mule-descriptor>
  • 24. Credit Agency Gateway The Credit Agency code is even easier! We use a standard Mule Component called a ReflectionMessageBuilder which builds a message based on a set of results from endpoint invocations. It will use reflection to determine how to set the result of the last endpoint invocation as a property on the master message. There are other MessageBuilder components such as the ScriptMessageBuilder component which is a JSR-223 (Scripting) component that allows you to manipulate the payload after each request using Groovy, JavaScript, Rhino or any other supported scripting language.
  • 25. Credit Agency Configuration <mule-descriptor name=&quot;CreditAgencyGateway&quot; implementation=&quot;org.mule.components.builder.ReflectionMessageBuilder&quot;> <inbound-router> <endpoint address=&quot; jms://credit.agency &quot;/> </inbound-router> <outbound-router> <router className=&quot;org.mule.routing.outbound.FilteringRouter&quot;> <endpoint address=&quot; ejb://localhost:1099/local/CreditAgency?method=getCreditProfile “ transformers=“ LoanQuoteRequestToCreditProfileArgs ” responseTransformers=&quot; CreditProfileXmlToCreditProfile “ /> <properties> <list name=&quot; methodArgumentTypes &quot;> <entry value=&quot;java.lang.String&quot;/> <entry value=&quot;java.lang.String&quot;/> </list> </properties> </endpoint> <endpoint address=&quot; jms://esb.lender.service &quot;/> </router> </outbound-router> </mule-descriptor>
  • 26. Credit Agency Configuration We invoke the CreditAgency application using an EJB endpoint – ejb://localhost:1099/local/CreditAgency?method=getCreditProfile This endpoint tells Mule to – Look up an EJB object at localhost:1099 Use the JNDI name local/CreditAgency Invoke the method getCreditProfile on the EJB object Notice also the transformers and responseTransformers attibutes on the endpoint. These tell Mule how to marshal for the Application. LoanQuoteRequestToCreditProfileArgs – Extracts the method arguments from the request as an array used to invoke getCreditProfile . CreditProfileXmlToCreditProfile – Parses the response Xml and creates a CreditProfile object that will be set on the LoanQuoteRequest .
  • 27. Lender Gateway Lender Service The Lender Agency is a Mule component, that receives events directly using the VM transport. Leander Gateway The Lender Gateway marshals requests from the bus to the lender service.
  • 28. Lender Gateway Configuration Lender Service <mule-descriptor name=&quot;LenderService&quot; implementation=&quot;org.mule.samples.loanbroker.esb.LenderService&quot;> <inbound-router> <endpoint address=&quot;vm://lender.service&quot;/> </inbound-router> </mule-descriptor> Lender Gatway <mule-descriptor name=&quot;LenderGateway” implementation=&quot;org.mule.components.simple.BridgeComponent&quot;> <inbound-router> <endpoint address=&quot;jms://esb.lender.service&quot;/> </inbound-router> <outbound-router> <router className=&quot;org.mule.routing.outbound.ChainingRouter&quot;> <endpoint address=&quot;vm://lender.service&quot;/> <endpoint address=&quot;jms://esb.banks&quot;/> </router> </outbound-router> </mule-descriptor>
  • 29. Banking Gateway The Banking Gateway is responsible for distributing requests to a list of lenders. The ReciptientList router configured on this gateway is responsible for extracting the endpoints from the message and invoking them. The RecipientList is a type of Itinerary-based router that extracts its itinerary as a static list from the event. <mule-descriptor name=&quot;BankingGateway&quot; implementation=&quot;org.mule.components.simple.BridgeComponent&quot;> <inbound-router> <endpoint address=&quot; jms://esb.banks &quot;/> </inbound-router> <outbound-router> <router className=&quot;org.mule.routing.outbound. StaticRecipientList &quot;> < reply-to address=&quot; jms://esb.loan.quotes &quot;/> </router> </outbound-router> </mule-descriptor>
  • 30. Banks The banks in this example are just simple beans that return a fixed interest rate and are exposed as SOAP services. <mule-descriptor name=&quot;Bank1&quot; inboundEndpoint=&quot; axis:http://localhost:10001/services &quot; implementation=&quot;org.mule.samples.loanbroker.Bank&quot;> </mule-descriptor> Note to expose a component as an Axis service all you need to do is add an Axis endpoint!
  • 31. Choosing the best Quote Once a back has a quote it passes it to Mule which will send the Quote on the reply-to endpoint specified by the Banking Gateway . Looking back at the LoanBroker configuration, there is a response-router configured as - <response-router timeout=&quot;10000&quot;> <endpoint address=&quot; jms://esb.loan.quotes &quot;/> <router className=&quot;org.mule.samples.loanbroker.esb.routers. BankQuotesResponseAggregator &quot;/> </response-router> The BankQuoteResponseAggregator is responsible for picking the lowest quote. But before that happens Mule needs to make sure all responses are received for the request. This is done using message correlation managed by Mule.
  • 32. Event Correlation When a event is dispatched from the Banking Gateway a correlationId and correlationGroupSize is attached to the SOAP message. This is a function of the Recipient List router. It attaches the following information - CorrelationId – and Id that associates all the dispatched events to the same group CorrelationGroupSize – how many events are in the group. CorrelationSequence – the order in which the events were dispatched. The Response Router reads these correlation headers when events are received and correlates the events. When the event group correlation is complete the response-router invokes itself where developers can plug in custom logic.
  • 33. Response Aggregation The BankQuoteResponseAggregator implements a single method that works out the lowest quote before passing it back to Mule to route the response back to the client. protected UMOMessage aggregateEvents(EventGroup events) throws RoutingException { . . . . List list = events.getEvents(); for (Iterator iterator = list.iterator(); iterator.hasNext();) { event = (UMOEvent) iterator.next(); quote = (LoanQuote)event.getTransformedMessage(); logger.info(&quot;Processing quote: &quot; + quote); if (lowestQuote == null) { lowestQuote = quote; } else if (quote.getInterestRate() < lowestQuote.getInterestRate()) { lowestQuote = quote; } } return new MuleMessage(lowestQuote, event.getProperties()); }
  • 34. Transports Most Mule transports can be configured using just the endpoint address. i.e. tcp://localhost:45454 contains all the information necessary to make a TCP connection. However for JMS and EJB we need to define configuration properties for each such as Jndi information. This is done by configuring connectors in our MuleXml.
  • 35. Transport Configuration EJB Connector (OpenEJB – Local Server. See http://openejb.org) <connector name=&quot;ejbConnector&quot; className=&quot;org.mule.providers.ejb.EjbConnector&quot;> <properties> <property name=&quot;jndiInitialFactory&quot; value=&quot;org.openejb.client.LocalInitialContextFactory&quot;/> <property name=&quot;securityPolicy&quot; value=&quot;security.policy&quot;/> <map name=&quot;jndiProviderProperties&quot;> <property name=&quot;openejb.base&quot; value=&quot;.&quot;/> <property name=&quot;openejb.configuration&quot; value=&quot;../conf/openejb.conf&quot;/> </map> </properties> </connector> JMS Connector (ActiveMQ) <connector name=&quot;jmsConnector&quot; className=&quot;org.mule.providers.jms.JmsConnector&quot;> <properties> <property name=&quot;connectionFactoryJndiName&quot; value=&quot;ConnectionFactory&quot;/> <property name=&quot;jndiInitialFactory&quot; value=&quot;org.activemq.jndi.ActiveMQInitialContextFactory&quot;/> <property name=&quot;specification&quot; value=&quot;1.1&quot;/> </properties> </connector>
  • 36. Fault Tolerance Exception Strategies Can be defined on components and connectors Can be defined globally of for each connector or component Can handle different exception types differently. Exception hierarchy provides all available information Event payloads can be re-routed on exception Connection Strategies Control how connectors connect to underlying resources Allow for flexible retry policies Notifications of failed connections Consistent endpoint state maintained Can alter routing paths based on failed connections
  • 37. Scaling SEDA Model Mule is SEDA-based, which is an architecture designed for high concurrency and throughput. JMS Clustering Currently Mule can use JMS clustering to distribute events to a cluster of Mule Nodes. Application Server Clustering Mule can be embedded inside a JCA container and allow the App server to manage its resources and cluster instances. New Clustering Support The next release of Mule will provide clustering and distribution using JGroups/JBossCache. Load Balancing using Mule You can use a Mule instance to provide load-balancing over any transport.
  • 38. Summary An ESB integrating a client application and 3 back office systems. Combined a number of transports including HTTP, JMS, EJB and Web Services. Easy to add in Exception handling, transactions, etc. All done through configuration. All event routing, management, transformation is handled by Mule. Very little code to write. Just domain-specific logic. A fully functional ESB in about an hour!
  • 39. The Mule Project Project was founded in 2003. It was started after experiences with a large Financial ESB project. There are now 10 developers who help support it and add new features. Has an active user community. Is being used in companies such as HP, Sony, Deutche Bank and CitiBank. SymphonySoft has been started by Mule developers to help support and provide professional services to these projects. For more information go to - http://mule.codehaus.org.
  • 40. Resources EIP Book (Loan Broker Example) [1][2] http://www.eaipatterns.com/ComposedMessagingExample.html http://www.eaipatterns.com/index.html Introduction to ESBs – Rick Robinson http://www-106.ibm.com/developerworks/xml/library/ws-esbscen/ ESB Learning Guide http://searchwebservices.techtarget.com/general/1,295582,sid26_gci1085711,00.html Introduction to SEDA – Matt Welsh http://www.eecs.harvard.edu/~mdw/papers/mdw-phdthesis.pdf Mule User Guide http://mule.codehaus.org/User+Guide
  • 41. Slides and Code To get this Loan Broker ESB code and these slides go to - http://mule.codehaus.org/LoanBroker There are other examples too - http://mule.codehaus.org/Examples