mule esb
TRANSCRIPT
MULE ESB
MULE ESB DEMO.
MULE REQUIRED S/WMULE BUILDING BLOCKSSET UP IDE/SWDEMO EXAMPLES
AGENDA
› What is Mule ESB?
Enterprise Service Bus (ESB) Easily perform integration of existing systems, Regardless of
technology.Service creation and hosting — expose and host reusable services. Service mediation- service mediator aids communication between
system-level service consumers and service providersMessage routing - route, filter, aggregate, and re-sequence messages
based on content and rules. Data transformation — exchange data across varying formats and
transport protocols
MULE ESB RECAP
Building blocks
› Components: are flexible tools which perform business logic implemented in Java and other scripting languages for e.g java component, javascript, groovy, echo, logger.
› Filters: only allow certain messages to continue to be processed in a flow for e.g .
› Routers: control message flow to route, resequence, or split and aggregate messages in a flow for e.g All flow, Choice flow.
› Scopes wrap other messages processors so as to enable them to perform together as a group. for e.g Async, Message Enricher, foreach.
› Transformers convert message payload type and data format to facilitate communication between systems converters. Object to String,Body to Parameter Map.
Message Processors
› To make decisions about routing, filtering, and other common tasks. The logic of these decisions often relies on evaluating expressions.
› Mule Expression Language (MEL) is the primary language used for formulating such expressions throughout Mule ESB.
SIGNIFICANCE MEL
› The message header, which contains metadata about the message › The message payload, which contains your business-specific data.
MULE MESSAGE
#[message.header.get()] This expression calls the "get" method and performs it on the object,
#[message.payload[4]] the expression returns the value of the 5th item in the list.
#[message.payload['type'].equals('XML')]
Check if param type is equals to XML
#[message.id] This expression accesses a particular attribute associated with the specified context object.
#[message.payload] Returns payload.
#[2 + 2 == 4] This expression uses an operator to perform a comparison. It evaluates to true.
MULE EXPRESSION LANGUAGE
› EndPoints› Ajax: this allows mule events to be asynchronously
received to and from web.› File: Allows mule application to read and write into local file
system.› Http: Allow mule events to be connected with http protocol.› Jms: Allow mule events to read and send message to
queue with JMS API.
Components
› Commonly Used Component› Use a Logger component to log activities in the flow as they occur. › Use an Expression component to evaluate a particular expression upon a
message in a flow.› Use an Echo component to return the payload of a message as a call
response.› Use a Flow Ref component to access another flow from within a flow.
Component cont.
› Mule message filters are message processors that follow the enterprise integration pattern called Message Filter.
Message Filters
› A filter that discards incoming HTTP requests
› ………<flow name="filteredFlow2">
<http:inbound-endpoint host="localhost" port="8000" path="orders"/><expression-filter expression="message.inboundProperties['Authorization'] != null"/><component class="org.my.OrderProcessingComponent" />
</flow>…..
Message filters cont.
› A choice router is a message processor that decides where to send a message based on their contents.
› A choice exception strategy is a way of deciding which way to route a message that must deviate from the normal processing path. Choice exception strategies use MEL expressions.
Choice routers
Choice routers cont.
› <flow name="downloadsSorterFlow">› <file:inbound-endpoint path="/home/me/downloads" />› <choice>› <when expression="#[message.inboundProperties['filename'].endsWith('.jpg']">› <file:outbound-endpoint path="/home/me/photos" />› </when>› <when expression="#[message.inboundProperties['filename'].endsWith('.doc')]">› <file:outbound-endpoint path="#[/home/me/docs" />› </when>› <otherwise>› <file:outbound-endpoint path="/home/me/misc"/>› </otherwise>› </choice>› </flow>
XML CONFIGURATION
› Mule invokes a Messaging Exception Strategy whenever an exception is thrown within a flow.
Exception STRATEGY
› An expression transformer is a message processor that executes expressions on the current message. The results of the expressions replace the payload.
› This transformer transforms the message by appending “Received !” to the message payload.
› <expression-transformer expression="#[message.payload + 'Received!']"/>
Expression transformers
› A logger is a message processor that logs message via Mules logging sub-system.
› The message to be logged is configured as an attribute of the logger. This message attribute supports tokens (placeholders). The tokens can contain MEL expressions.
<loggermessage="File Received (size = #[message.inboundProperties['fileSize']/1024] kb)"level="INFO"
/>
Loggers
› Extract the downloaded MuleStudio binary into a folder› Go to bin folder Run MuleStudio.exe› To create new project file->mule project
SETUP IDE
Project structure
• CONTENT BASED ROUTING• JMS EXAMPLE• STRATEGIC EXCEPTION
DEMO
› Flow
Choice example
• Import a project into a mule studio choice example.• Right click on the project –start as mule project• Watch the logs whether project is deployed successfully.• Execute following url to get XML response• http://localhost:1001/?
name=Muley&amount=20000&term=48&ssn=1234&type=XML• Execute following url to get different response• http://localhost:1001/?
name=Muley&amount=20000&term=48&ssn=1234&type=othervalue
How to run
JMS Example
› Start Apache mq› Import jmsexample into mule studio, deploy the project.› Open http://localhost:8161/admin/queues.jsp . click on send tab,
Message gui will appear, select queue as queue1 and set body content either 1001 or 1002 or 1003 for valid content or other value to set error messages .
› Watch console logs, payload for each flow will appear.› Success message will enqueue in customerqueue› Error message will enqueue in errorqueue
Steps to run
CATCH EXCEPTION
› Start Apache mq› Import catchexception strategy into mule studio, deploy the
project by running project as mule application.› Open http://localhost:8161/admin/queues.jsp . click on
send tab, Message gui will appear, select queue as queue1 and set body content either ERROR OR TEST OR othervalue
› Watch console logs, payload for each flow will appear.
Steps to run
› MEL http://www.mulesoft.org/documentation/display/current/Introduction+to+Expressions+in+Mule
› Cheat Sheatttp://www.mulesoft.org/documentation/display/current/MEL+Cheat+Sheet› Transformershttp://www.mulesoft.org/documentation/display/current/Transformers
ESB References