take mule 3 for a ride

53
Taking Mule 3 for a Ride Ross Mason

Upload: ross-mason

Post on 10-May-2015

11.668 views

Category:

Technology


4 download

DESCRIPTION

Walks through some of the new features of Mule 3 including cloud connect, Flow, AJAX and JavaScript support, REST and Web Services and the new deployment model

TRANSCRIPT

Page 1: Take Mule 3 For A Ride

Taking Mule 3 for a RideRoss Mason

Page 2: Take Mule 3 For A Ride

What is Mule?

All contents Copyright © 2009, MuleSoft Inc. 2

Page 3: Take Mule 3 For A Ride

All contents Copyright © 2009, MuleSoft Inc. 3

Not a donkey

Page 4: Take Mule 3 For A Ride

All contents Copyright © 2009, MuleSoft Inc. 4

Not a llama

Page 5: Take Mule 3 For A Ride

All contents Copyright © 2009, MuleSoft Inc. 5

Not a camel

Page 6: Take Mule 3 For A Ride

BaaS: Beer As A Service

All contents Copyright © 2009, MuleSoft Inc. 6

Page 7: Take Mule 3 For A Ride

BaaS

All contents Copyright © 2009, MuleSoft Inc. 7

Page 8: Take Mule 3 For A Ride

BaaS

All contents Copyright © 2009, MuleSoft Inc. 8

Page 9: Take Mule 3 For A Ride

BaaS

All contents Copyright © 2009, MuleSoft Inc. 9

Page 10: Take Mule 3 For A Ride

Mule Platform

All contents Copyright © 2009, MuleSoft Inc. 10

SEDA EngineRoutingSecurity

Core Platform

SchedulingDeployment

Transform

Error Handling

Cloud Connect

REST, WS PatternsFlow

Data Feeds

ContainerServices

Connectivity

Bindings: JSON/XML

Messaging Database FTP/File Applications

AJAX / JS

Page 11: Take Mule 3 For A Ride

AJAX – Hook the ESB to the Browser

Real time events to the Browser

Trigger ESB events from the Browser

Simple Set up, no need for App Server

JSON Support– Object Binding

– Transformers

– Query Language

JavaScript client for Mule ESB

All contents Copyright © 2009, MuleSoft Inc. 11

AJAX / JS

Page 12: Take Mule 3 For A Ride

AJAX – Hook the ESB to the Browser

All contents Copyright © 2009, MuleSoft Inc. 12

<ajax:connector name="ajax" serverUrl="http://localhost:8081/foo”/> <flow name=”AjaxService"> <vm:inbound-endpoint path="in"/> <component class="org.foo.MyComponent"/> <ajax:outbound-endpoint channel="/test"/> </flow>

Mule Config (Server)

<script type="text/javascript" src="mule-resource/js/mule.js”/>

mule.subscribe("/test", callback);

function callback(coord) { //do stuff}

Mule JS Client (Browser)

Page 13: Take Mule 3 For A Ride

Cloud Connect

Integrate with stuff on the net– Grab data from SaaS platforms

– Utilise infrastructure Services

– Connect to Social Media platforms

Uses IBeans (open source project)– Provide a strongly typed interface to a service

Support for REST and Web Services

Data bindings using XML and JSON

All contents Copyright © 2009, MuleSoft Inc. 13

Cloud Connect

Page 14: Take Mule 3 For A Ride

Cloud Connect

All contents Copyright © 2009, MuleSoft Inc. 14

Page 15: Take Mule 3 For A Ride

Cloud Connect

public class MyComponent {

@IntegrationBean

private S3IBean s3iBean;

@PostConstruct

public void init() throws Exception {

s3iBean.init("${aws.s3.access.key}", "${aws.s3.secret.key}");

s3iBean.createBucket("test", BucketLocation.US);

}

. . .

}

All contents Copyright © 2009, MuleSoft Inc. 15

Inject an Amazon S3 Integration Bean

Create a new bucket store on S3

Pass in your S3 credentials

Page 16: Take Mule 3 For A Ride

Mule Flow

Fluid DSL for creating message flows

Fixes the ‘S’ in SOA– Easier to think about what rather than how

Mix and match routing, transforms, components

Much less configuration than Mule 2

All contents Copyright © 2009, MuleSoft Inc. 16

Flow

Page 17: Take Mule 3 For A Ride

<flow>

All contents Copyright © 2009, MuleSoft Inc. 17

Page 18: Take Mule 3 For A Ride

<flow> intro

<flow name=“BeerAsAService"> <inbound-endpoint address="http://localhost:9090/brew" exchange-pattern="request-response"/> <append-string-transformer message="Ordering, "/> <append-string-transformer message="Brewing me some beer, "/> <append-string-transformer message="Shipping"/></flow>

Result: Ordering, Brewing me some beer, Shipping

All contents Copyright © 2009, MuleSoft Inc. 18

Page 19: Take Mule 3 For A Ride

<choice>

<flow name=“BeerAsAService"> <inbound-endpoint address="http://localhost:9090/brew" exchange-pattern="request-response"/> <choice> <when expression="#[groovy:payload == 'IPA']"> <append-string-transformer message="Using recipe with extra hops, "/> </when> <otherwise> <append-string-transformer message="Using normal recipe, "/> </otherwise> </choice>…</flow>

All contents Copyright © 2009, MuleSoft Inc. 19

Page 20: Take Mule 3 For A Ride

<async>

<flow name="BeerAsync"> <inbound-endpoint address="http://localhost:9090/async" exchange-pattern="request-response"/> <append-string-transformer message="Ordering, "/> <append-string-transformer message="Brewing me some beer, "/> <async> <expression-transformer> <return-argument expression="'Drinking me some beer'" evaluator=”string"/> </expression-transformer> <stdio:outbound-endpoint system="OUT" /> </async> <append-string-transformer message="Shipping"/></flow>

All contents Copyright © 2009, MuleSoft Inc. 20

Page 21: Take Mule 3 For A Ride

<all>

<flow name=“NotifyStaffDrinkers"> <inbound-endpoint address="http://localhost:9090/all" exchange-pattern="request-response"/> <append-string-transformer message="Ordering, "/> <append-string-transformer message="Brewing me some beer, "/> <all> <outbound-endpoint address="vm://staffDrinker1"/> <outbound-endpoint address="vm://staffDrinker2"/> </all> <append-string-transformer message="Shipping"/></flow>

All contents Copyright © 2009, MuleSoft Inc. 21

Page 22: Take Mule 3 For A Ride

Composable, reusable

<flow name="CustomMP"> <inbound-endpoint address="http://localhost:9090/custom-mp" exchange-pattern="request-response"/> <append-string-transformer message="Ordering, "/> <flow-ref name="Brewing"/> <append-string-transformer message="Shipping"/></flow>

<flow name="Brewing"> <!-- Do brewing --> <append-string-transformer message="Brewing me some beer, "/></flow>

All contents Copyright © 2009, MuleSoft Inc. 22

Page 23: Take Mule 3 For A Ride

<service> still supported! But, compare to Mule 2.x...

All contents Copyright © 2009, MuleSoft Inc. 23

Page 24: Take Mule 3 For A Ride

Loanbroker: Service vs Flow

<!--

The loan broker is used to receive loan requests

-->

<service name="TheLoanBroker">

<inbound>

<inbound-endpoint ref="CustomerRequests"/>

</inbound>

<component class="org.mule.example.loanbroker.esn.SynchronousLoanBroker">

<binding interface="org.mule.example.loanbroker.credit.CreditAgencyService">

<outbound-endpoint ref="CreditAgency"/>

</binding>

</component>

<outbound>

<pass-through-router>

<outbound-endpoint ref="LenderService"/>

</pass-through-router>

</outbound>

<async-reply timeout="1000000">

<inbound-endpoint ref="LoanBrokerQuotes"/>

<custom-async-reply-router class="org.mule.example.loanbroker.routers.BankQuotesResponseAggregator"/>

</async-reply>

</service>

<!--

The credit agency service will get the credit profile for a customer

-->

<service name="TheCreditAgencyService">

<inbound>

<inbound-endpoint ref="CreditAgencyIn"/>

</inbound>

<component class="org.mule.example.loanbroker.credit.DefaultCreditAgency"/>

</service>

<!--

The Lender service is used to determine which banks to contact for a quote

-->

<service name="TheLenderService">

<inbound>

<inbound-endpoint ref="LenderService"/>

</inbound>

<component class="org.mule.example.loanbroker.lender.DefaultLender"/>

<outbound>

<pass-through-router>

<outbound-endpoint ref="BankGateway" transformer-refs="SetLendersAsRecipients"/>

</pass-through-router>

</outbound>

</service>

<service name="TheBankGateway">

<inbound>

<inbound-endpoint ref="BankGateway"/>

<forwarding-router/>

</inbound>

<outbound>

<static-recipient-list-router>

<reply-to address="LoanBrokerQuotes"/>

<message-property-filter pattern="recipients!=null"/>

</static-recipient-list-router>

<logging-catch-all-strategy/>

</outbound>

</service>

<flow name="loan-broker">

<inbound-endpoint ref="CustomerRequests" exchange-pattern="request-response" />

<component class="org.mule.example.loanbroker.esn.SynchronousLoanBroker">

<binding interface="org.mule.example.loanbroker.credit.CreditAgencyService">

<outbound-endpoint ref="CreditAgency" exchange-pattern="request-response" />

</binding>

</component>

<component class="org.mule.example.loanbroker.lender.DefaultLender" />

<expression-filter expression="payload.lenders.endpoint!=null" evaluator="groovy" />

<request-reply timeout="10000">

<recipient-list evaluator="groovy" expression="payload.lenders.endpoint"/>

<inbound-endpoint ref="LoanBrokerQuotes">

<custom-aggregator class="org.mule.example.loanbroker.routers.BankQuotesResponseAggregator" />

</inbound-endpoint>

</request-reply>

</flow>

All contents Copyright © 2009, MuleSoft Inc. 24

Page 25: Take Mule 3 For A Ride

Mule Patterns

Bigger Building Blocks– A level above EIP

Reduces the amount of Config

Built in the Core of Mule– Users can add their own

– Can be abstract

Good for working with external Teams

All contents Copyright © 2009, MuleSoft Inc. 25

Patterns

Page 26: Take Mule 3 For A Ride

Patterns – Simple Service

All contents Copyright © 2009, MuleSoft Inc. 26

<simple-service name="weather-service" address="http://localhost:6099/weather" component-class="org.mule.test.WeatherForecaster" type="jax-rs" />

Create a JAX-RS service, also supports JAX-WS

Configured with JAX-RS annotations

Use Case: Using Mule as a deployment platform for business services.

Page 27: Take Mule 3 For A Ride

Pattern - Web-Service Proxy

Use Case:

• Exposes an external web-service internally, while optionally performing transformations on

the SOAP envelope.

• Supports WSDL proxying (with rewriting of the port address component) and overriding

(with usage of a provided WSDL).

All contents Copyright © 2009, MuleSoft Inc. 27

<ws:proxy name="beer-ws-proxy“ inboundAddress="http://localhost/beer-ws" outboundAddress="http://nogne-o.com/beer-ws" wsdlFile="localWsdl.wsdl" />

Page 28: Take Mule 3 For A Ride

Pattern - Web-Service Proxy in Mule 2

<spring:bean name="WSProxyService" class="org.mule.transport.soap.WSProxyService">

<spring:property name="wsdlFile" value="localWsdl.wsdl"/>

</spring:bean>

<service name="httpWebServiceProxy">

<inbound>

<inbound-endpoint address="http://localhost:8080/my/service"

synchronous="true"/>

</inbound>

<component>

<spring-object bean="WSProxyService" />

</component>

<outbound>

<pass-through-router>

<outbound-endpoint

address=http://acme.come/remote/web/service synchronous="true"/>

</pass-through-router>

</outbound>

</service>

All contents Copyright © 2009, MuleSoft Inc. 28

Page 29: Take Mule 3 For A Ride

Pattern - Web-Service Proxy

All contents Copyright © 2009, MuleSoft Inc. 29

Page 30: Take Mule 3 For A Ride

Pattern - Web-Service Proxy

<mulexml:xslt-transformer name="v1-to-v2" xsl-file="v1-to-v2.xsl"/><mulexml:xslt-transformer name="v2-to-v1" xsl-file="v2-to-v1.xsl"/> <ws:proxy name="beer-ws-proxy“ inboundAddress="http://localhost/beer-ws" outboundAddress="http://nogne-o.com/beer-ws" transformer-refs="v2-to-v1" responseTransformer-refs="v1-to-v2” wsdlFile=”beer.wsdl" />

All contents Copyright © 2009, MuleSoft Inc. 30

Page 31: Take Mule 3 For A Ride

Pattern - Bridge

Use Case: Transactional synchronous bridge, for example: JMS bridging (topic to queue)

All contents Copyright © 2009, MuleSoft Inc. 31

<bridge name="transacted-bridge" transacted="true" inboundAddress=”wmq://test.In" outboundAddress="jms://test.Out" />

Page 32: Take Mule 3 For A Ride

REST

Uses Jersey– JAX-RS reference implementation

Build correct RESTful services

Lightweight, easy to use

All contents Copyright © 2009, MuleSoft Inc. 32

REST, WS

Page 33: Take Mule 3 For A Ride

REST: Why Jersey in Mule?

Wrap in a transaction, send off to JMS

Implement custom routing rules based on URLs

Mule security

Easily transform old versions

All contents Copyright © 2009, MuleSoft Inc. 33

Page 34: Take Mule 3 For A Ride

Service Class

@Path("/")public class BeerOnDemand{ @POST @Consumes({ "application/json" }) @Produces({ "application/json" }) public OrderStatus order(Order order) { // return a status return …; } @GET @Produces({ "application/json" }) public String brew() { return "Brewing!"; }}

All contents Copyright © 2009, MuleSoft Inc. 34

Page 35: Take Mule 3 For A Ride

Jersey Resources

<flow name="BeerAsARestService"> <inbound-endpoint address="http://localhost:9090/jersey"/> <jersey:resources> <component class="com.mulesoft.beer.BeerOnDemand"/> <component class="com.mulesoft.beer.CustomerPortal"/> </jersey:resources></flow>

All contents Copyright © 2009, MuleSoft Inc. 35

Page 36: Take Mule 3 For A Ride

Easy REST client with JSON

<flow name="OrderPlacer">…

<json:object-to-json /> <response> <json:json-to-object returnClass="com.mulesoft.beer.Order" /> </response> <outbound-endpoint address="http://localhost:9090/rest-beer"/></flow>

All contents Copyright © 2009, MuleSoft Inc. 36

Page 37: Take Mule 3 For A Ride

On the wire

Object

public class Order {

private String

customer;

private intcases;

}

JSON

{

“customer” : “Dan”

“cases” : 300

}

All contents Copyright © 2009, MuleSoft Inc. 37

Page 38: Take Mule 3 For A Ride

Web Services

Web Services are a PITA– Mule 3 makes them easier

Host and Consume Web services

Decoupled Transport from Protocol– Receive / Send over JMS, email, etc

JAX-WS or Simple

Easy to Proxy and modify

All contents Copyright © 2009, MuleSoft Inc. 38

REST, WS

Page 39: Take Mule 3 For A Ride

Hosting web services

<flow name="BeerAsAWebService"> <inbound-endpoint address="http://localhost:9090/ws"/> <cxf:jaxws-service serviceClass="com.mulesoft.beer.BeerOnDemand"/> <component class="com.mulesoft.beer.BeerOnDemand"/></flow>

All contents Copyright © 2009, MuleSoft Inc. 39

Page 40: Take Mule 3 For A Ride

Web Services: Improved XML configuration

Page 41: Take Mule 3 For A Ride

Web Services: Improved XML configuration

Page 42: Take Mule 3 For A Ride

Flexible, Scriptable

<flow name="BeerAsAWebService"> <inbound-endpoint address="http://localhost:9090/ws-async"/> <cxf:jaxws-service serviceClass="com.mulesoft.beer.BeerOnDemand"/> <expression-transformer> <return-argument expression="'Processing ' + payload[0] + ' orders'" evaluator="groovy"/> </expression-transformer></flow>

All contents Copyright © 2009, MuleSoft Inc. 42

Page 43: Take Mule 3 For A Ride

MESSAGE PROCESSORSHow does this all work?

All contents Copyright © 2009, MuleSoft Inc. 43

Page 44: Take Mule 3 For A Ride

Message Processors and Flows

All contents Copyright © 2009, MuleSoft Inc. 44

Page 45: Take Mule 3 For A Ride

Custom MPs

<flow name=“BeerAsAService"> <inbound-endpoint address="http://localhost:9090/brew"/> <custom-processor class="com.mulesoft.beer.BrewerMessageProcessor"/></flow>

All contents Copyright © 2009, MuleSoft Inc. 45

Page 46: Take Mule 3 For A Ride

For example….

public class BrewerMessageProcessor implements MessageProcessor{ public MuleEvent process(MuleEvent event) throws MuleException { event.getMessage().setPayload( "Yup, fermentin' me some beer."); return event; }}

All contents Copyright © 2009, MuleSoft Inc. 46

Page 47: Take Mule 3 For A Ride

For example….

public class BrewerMessageProcessor extends AbstractInteceptingMessageProcessor{ public MuleEvent process(MuleEvent event) throws MuleException { event.getMessage().setPayload( "Yup, fermentin' me some beer."); MuleEvent response = processNext(event);

event.getMessage().setPayload( “300 cases brewed."); return respones; }}

All contents Copyright © 2009, MuleSoft Inc. 47

Page 48: Take Mule 3 For A Ride

HOT DEPLOYMENTMoving in when the time is right

All contents Copyright © 2009, MuleSoft Inc. 48

Page 49: Take Mule 3 For A Ride

Pragmatic

#NoOSGi

Not another app server

All contents Copyright © 2009, MuleSoft Inc. 49

Page 50: Take Mule 3 For A Ride

Applications are zips

Apps are zips or exploded directories

By convention: most parts are optional

All contents Copyright © 2009, MuleSoft Inc. 50

Page 51: Take Mule 3 For A Ride

Deployment Descriptor

domain

config.resources

redeployment.enabled

encoding

config.builder

All contents Copyright © 2009, MuleSoft Inc. 51

Page 52: Take Mule 3 For A Ride

Maven Plugin

<project>... <packaging>mule</packaging>...</project>

All contents Copyright © 2009, MuleSoft Inc. 52

Page 53: Take Mule 3 For A Ride

Questions?

web: http://mulesoft.orgtwitter: @rossjmason

email: [email protected]

All contents Copyright © 2009, MuleSoft Inc. 53