mule esb

28
MULE ESB MULE ESB DEMO.

Upload: sathyaraj-anand

Post on 16-Apr-2017

129 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: Mule esb

MULE ESB

MULE ESB DEMO.

Page 2: Mule esb

MULE REQUIRED S/WMULE BUILDING BLOCKSSET UP IDE/SWDEMO EXAMPLES

AGENDA

Page 3: Mule esb

› 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

Page 4: Mule esb

Building blocks

Page 5: Mule esb

› 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

Page 6: Mule esb

› 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

Page 7: Mule esb

› The message header, which contains metadata about the message › The message payload, which contains your business-specific data.

MULE MESSAGE

Page 8: Mule esb

#[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

Page 9: Mule esb

› 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

Page 10: Mule esb

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

Page 11: Mule esb

› Mule message filters are message processors that follow the enterprise integration pattern called Message Filter.

Message Filters

Page 12: Mule esb

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

Page 13: Mule esb

› 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

Page 14: Mule esb

Choice routers cont.

Page 15: Mule esb

› <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

Page 16: Mule esb

› Mule invokes a Messaging Exception Strategy whenever an exception is thrown within a flow.

Exception STRATEGY

Page 17: Mule esb

› 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

Page 18: Mule esb

› 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

Page 19: Mule esb

› Extract the downloaded MuleStudio binary into a folder› Go to bin folder Run MuleStudio.exe› To create new project file->mule project

SETUP IDE

Page 20: Mule esb

Project structure

Page 21: Mule esb

• CONTENT BASED ROUTING• JMS EXAMPLE• STRATEGIC EXCEPTION

DEMO

Page 22: Mule esb

› Flow

Choice example

Page 23: Mule esb

• 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

Page 24: Mule esb

JMS Example

Page 25: Mule esb

› 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

Page 26: Mule esb

CATCH EXCEPTION

Page 27: Mule esb

› 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

Page 28: Mule esb

› 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