Setup up for your QCON Pro & QCON EX controller section Note:
Mule Enterprise to the Web - QCon San Francisco · Bringing the enterprise to the web with Mule. So...
Transcript of Mule Enterprise to the Web - QCon San Francisco · Bringing the enterprise to the web with Mule. So...
![Page 1: Mule Enterprise to the Web - QCon San Francisco · Bringing the enterprise to the web with Mule. So RESTful ... Supports a variety of service topologies including ESB Highly ... –](https://reader034.fdocuments.in/reader034/viewer/2022051601/5abf20e97f8b9ab02d8dcb26/html5/thumbnails/1.jpg)
the open source choice for SOA infrastructure
Bringing the enterprise to the web with Mule
![Page 2: Mule Enterprise to the Web - QCon San Francisco · Bringing the enterprise to the web with Mule. So RESTful ... Supports a variety of service topologies including ESB Highly ... –](https://reader034.fdocuments.in/reader034/viewer/2022051601/5abf20e97f8b9ab02d8dcb26/html5/thumbnails/2.jpg)
So RESTful services are cool….
All contents Copyright 2008, MuleSource Inc. 2
![Page 3: Mule Enterprise to the Web - QCon San Francisco · Bringing the enterprise to the web with Mule. So RESTful ... Supports a variety of service topologies including ESB Highly ... –](https://reader034.fdocuments.in/reader034/viewer/2022051601/5abf20e97f8b9ab02d8dcb26/html5/thumbnails/3.jpg)
Challenges
Middleware is oriented around WS-* still
Consuming and buildilng RESTful services has typically been Consuming and buildilng RESTful services has typically been more difficult than it needs to be
Messaging vs. REST
All contents Copyright 2008, MuleSource Inc. 3
![Page 4: Mule Enterprise to the Web - QCon San Francisco · Bringing the enterprise to the web with Mule. So RESTful ... Supports a variety of service topologies including ESB Highly ... –](https://reader034.fdocuments.in/reader034/viewer/2022051601/5abf20e97f8b9ab02d8dcb26/html5/thumbnails/4.jpg)
Mule Manufacturing Co.
All contents Copyright 2008, MuleSource Inc. 4
![Page 5: Mule Enterprise to the Web - QCon San Francisco · Bringing the enterprise to the web with Mule. So RESTful ... Supports a variety of service topologies including ESB Highly ... –](https://reader034.fdocuments.in/reader034/viewer/2022051601/5abf20e97f8b9ab02d8dcb26/html5/thumbnails/5.jpg)
SOA Swiss Army Knife
Supports a variety of service topologies including ESB
Highly Scalable; using SEDA event model
Asynchronous, Synchronous and Request/Response Messaging
J2EE Support: JBI, JMS, EJB, JCA, JTA, Servlet
Powerful event routing capabilities (based on EIP book)
Breadth of connectivity; 60+ technologiesBreadth of connectivity; 60+ technologies
Transparent Distribution
Transactions; Local and Distributed (XA)
Fault tolerance; Exception management
Secure; Authentication/Authorization
![Page 6: Mule Enterprise to the Web - QCon San Francisco · Bringing the enterprise to the web with Mule. So RESTful ... Supports a variety of service topologies including ESB Highly ... –](https://reader034.fdocuments.in/reader034/viewer/2022051601/5abf20e97f8b9ab02d8dcb26/html5/thumbnails/6.jpg)
Why do developers choose Mule?
No prescribed message format– XML, CSV, Binary, Streams, Record, Java Objects– Mix and match
Zero code intrusion– Mule does not impose an API on service objects– Objects are fully portable– Objects are fully portable
Existing objects can be managed– POJOs, IoC Objects, EJB Session Beans, Remote Objects– REST / Web Services
Easy to test– Mule can be run easily from a JUnit test case– Framework provides a Test compatibility kit– Scales down as well as up
![Page 7: Mule Enterprise to the Web - QCon San Francisco · Bringing the enterprise to the web with Mule. So RESTful ... Supports a variety of service topologies including ESB Highly ... –](https://reader034.fdocuments.in/reader034/viewer/2022051601/5abf20e97f8b9ab02d8dcb26/html5/thumbnails/7.jpg)
Mule Services
All contents Copyright 2008, MuleSource Inc. 7
![Page 8: Mule Enterprise to the Web - QCon San Francisco · Bringing the enterprise to the web with Mule. So RESTful ... Supports a variety of service topologies including ESB Highly ... –](https://reader034.fdocuments.in/reader034/viewer/2022051601/5abf20e97f8b9ab02d8dcb26/html5/thumbnails/8.jpg)
Core Concepts: Endpoints
Used to connect components and external systems togetherEndpoints use a URI for AddressingCan have transformer, transaction, filter, security and meta-information associatedsecurity and meta-information associatedTwo types of URI– scheme://[username][:password]@[host][:port]
?[params]• smtp://ross:pass@localhost:25
– scheme://[address]?[params]• jms://my.queue?persistent=true
![Page 9: Mule Enterprise to the Web - QCon San Francisco · Bringing the enterprise to the web with Mule. So RESTful ... Supports a variety of service topologies including ESB Highly ... –](https://reader034.fdocuments.in/reader034/viewer/2022051601/5abf20e97f8b9ab02d8dcb26/html5/thumbnails/9.jpg)
Core Concepts: Routers
Control how events are sent and receivedCan model all routing patterns defined in the EIP BookInbound Routers– Idempotency– Selective Consumers– Re-sequencing– Re-sequencing– Message aggregation
Outbound Routers– Message splitting / Chunking– Content-based Routing– Broadcasting– Rules-based routing– Load Balancing
![Page 10: Mule Enterprise to the Web - QCon San Francisco · Bringing the enterprise to the web with Mule. So RESTful ... Supports a variety of service topologies including ESB Highly ... –](https://reader034.fdocuments.in/reader034/viewer/2022051601/5abf20e97f8b9ab02d8dcb26/html5/thumbnails/10.jpg)
Core Concepts: Transformers
Transformers– Converts data from one format to another– Can be chained together to form transformation pipelines– Can be chained together to form transformation pipelines
<jms:object-to-jms name="XmlToJms" />
<custom-transformer name="CobolXmlToBusXml"class= "com.myco.trans.CobolXmlToBusXml" />
<endpoint address= "jms://trades"transformers= "CobolXmlToBusXml, XmlToJms" />
![Page 11: Mule Enterprise to the Web - QCon San Francisco · Bringing the enterprise to the web with Mule. So RESTful ... Supports a variety of service topologies including ESB Highly ... –](https://reader034.fdocuments.in/reader034/viewer/2022051601/5abf20e97f8b9ab02d8dcb26/html5/thumbnails/11.jpg)
BUILDING SERVICES
All contents Copyright 2008, MuleSource Inc. 11
![Page 12: Mule Enterprise to the Web - QCon San Francisco · Bringing the enterprise to the web with Mule. So RESTful ... Supports a variety of service topologies including ESB Highly ... –](https://reader034.fdocuments.in/reader034/viewer/2022051601/5abf20e97f8b9ab02d8dcb26/html5/thumbnails/12.jpg)
Jersey
Annotations to expose your classes as a RESTful service
Implements the JAX-RS (JSR311) specificationImplements the JAX-RS (JSR311) specification
Mule connector makes it possible to embed JAX-RS services in Mule
All contents Copyright 2008, MuleSource Inc. 12
![Page 13: Mule Enterprise to the Web - QCon San Francisco · Bringing the enterprise to the web with Mule. So RESTful ... Supports a variety of service topologies including ESB Highly ... –](https://reader034.fdocuments.in/reader034/viewer/2022051601/5abf20e97f8b9ab02d8dcb26/html5/thumbnails/13.jpg)
@Path( "/helloworld" )
public class HelloWorldResource {
@GET
@ProduceMime( "text/plain" )
public String sayHelloWorld() {
return "Hello World" ;
}
}
All contents Copyright 2008, MuleSource Inc. 13
![Page 14: Mule Enterprise to the Web - QCon San Francisco · Bringing the enterprise to the web with Mule. So RESTful ... Supports a variety of service topologies including ESB Highly ... –](https://reader034.fdocuments.in/reader034/viewer/2022051601/5abf20e97f8b9ab02d8dcb26/html5/thumbnails/14.jpg)
@POST
@Produces ( "application/xml" )
@Consumes( "application/xml" )
public Response placeOrder(Order order) {
int number = getNextOrderNumber() ;
……
URI location = uriInfo .getAbsolutePath()
.resolve( "/orders/" + number);
return Response. created(location)
.entity(order)
.build();
}
All contents Copyright 2008, MuleSource Inc. 14
![Page 15: Mule Enterprise to the Web - QCon San Francisco · Bringing the enterprise to the web with Mule. So RESTful ... Supports a variety of service topologies including ESB Highly ... –](https://reader034.fdocuments.in/reader034/viewer/2022051601/5abf20e97f8b9ab02d8dcb26/html5/thumbnails/15.jpg)
@GET
@Produces( "application/xml" )
@Path( "/{id}" )@Path( "/{id}" )
public Order getOrder( @PathParam( "id" ) int id) {
return orders.get(id);
}
All contents Copyright 2008, MuleSource Inc. 15
![Page 16: Mule Enterprise to the Web - QCon San Francisco · Bringing the enterprise to the web with Mule. So RESTful ... Supports a variety of service topologies including ESB Highly ... –](https://reader034.fdocuments.in/reader034/viewer/2022051601/5abf20e97f8b9ab02d8dcb26/html5/thumbnails/16.jpg)
Mule Configuration
<service name=“orderResource" >
<inbound >
<inbound-endpoint
address =" jersey:http ://localhost:63081/orders" />address =" jersey:http ://localhost:63081/orders" />
</ inbound >
<component
class ="org.mule.examples.mfg.OrderResource" />
</ service >
All contents Copyright 2008, MuleSource Inc. 16
![Page 17: Mule Enterprise to the Web - QCon San Francisco · Bringing the enterprise to the web with Mule. So RESTful ... Supports a variety of service topologies including ESB Highly ... –](https://reader034.fdocuments.in/reader034/viewer/2022051601/5abf20e97f8b9ab02d8dcb26/html5/thumbnails/17.jpg)
Why Jersey?
Very easy to build RESTful services inside Mule
Built in serialization support for– XML via JAXB
– JSON
– Images
– Easily write your own serializers
All contents Copyright 2008, MuleSource Inc. 17
![Page 18: Mule Enterprise to the Web - QCon San Francisco · Bringing the enterprise to the web with Mule. So RESTful ... Supports a variety of service topologies including ESB Highly ... –](https://reader034.fdocuments.in/reader034/viewer/2022051601/5abf20e97f8b9ab02d8dcb26/html5/thumbnails/18.jpg)
INTEGRATING REST INTO YOUR MESSAGING LAYER
All contents Copyright 2008, MuleSource Inc. 18
![Page 19: Mule Enterprise to the Web - QCon San Francisco · Bringing the enterprise to the web with Mule. So RESTful ... Supports a variety of service topologies including ESB Highly ... –](https://reader034.fdocuments.in/reader034/viewer/2022051601/5abf20e97f8b9ab02d8dcb26/html5/thumbnails/19.jpg)
Process flow
Order Resource
POST Order
All contents Copyright 2008, MuleSource Inc. 19
Resource
HTTP response
Internal order processing
queue
![Page 20: Mule Enterprise to the Web - QCon San Francisco · Bringing the enterprise to the web with Mule. So RESTful ... Supports a variety of service topologies including ESB Highly ... –](https://reader034.fdocuments.in/reader034/viewer/2022051601/5abf20e97f8b9ab02d8dcb26/html5/thumbnails/20.jpg)
<!-- Is this a new order? If so, initiate the backend
processing -->
<filtering-router >
<outbound-endpoint address ="vm://processOrder" />
<and- filter >
<restlet:uri-template-filter
verbs ="POST" pattern ="/orders" />
<expression-filter
evaluator ="header" expression ="http.status=201" />
</ and-filter >
</ filtering-router >
All contents Copyright 2008, MuleSource Inc. 20
![Page 21: Mule Enterprise to the Web - QCon San Francisco · Bringing the enterprise to the web with Mule. So RESTful ... Supports a variety of service topologies including ESB Highly ... –](https://reader034.fdocuments.in/reader034/viewer/2022051601/5abf20e97f8b9ab02d8dcb26/html5/thumbnails/21.jpg)
Another example: URI template routing
<service name="webServices" >
<inbound >
<inbound-endpoint address ="http://localhost:63080"
remoteSync ="true" />
</ inbound >
<outbound >
<filtering-router >
<outbound-endpoint address ="vm://orderQueue" />
<restlet:uri-template-filter pattern ="/orders/{orderId}" />
</ filtering-router >
<filtering-router >
<outbound-endpoint address ="vm://userQueue" />
<restlet:uri-template-filter pattern ="/users" />
</ filtering-router >
</ outbound >
</ service >
All contents Copyright 2008, MuleSource Inc. 21
![Page 22: Mule Enterprise to the Web - QCon San Francisco · Bringing the enterprise to the web with Mule. So RESTful ... Supports a variety of service topologies including ESB Highly ... –](https://reader034.fdocuments.in/reader034/viewer/2022051601/5abf20e97f8b9ab02d8dcb26/html5/thumbnails/22.jpg)
Modify messages while filtering!
<restlet:uri-template-filter
pattern ="/ orderId /{set - header.orderId }" />pattern ="/ orderId /{set - header.orderId }" />
<restlet:uri-template-filter
pattern ="/orderId/{set-payload.orderId}" />
All contents Copyright 2008, MuleSource Inc. 22
![Page 23: Mule Enterprise to the Web - QCon San Francisco · Bringing the enterprise to the web with Mule. So RESTful ... Supports a variety of service topologies including ESB Highly ... –](https://reader034.fdocuments.in/reader034/viewer/2022051601/5abf20e97f8b9ab02d8dcb26/html5/thumbnails/23.jpg)
Order Processing
Order processing
queue
Warehouse Log business
All contents Copyright 2008, MuleSource Inc. 23
Warehouse availability
check
Log business events
![Page 24: Mule Enterprise to the Web - QCon San Francisco · Bringing the enterprise to the web with Mule. So RESTful ... Supports a variety of service topologies including ESB Highly ... –](https://reader034.fdocuments.in/reader034/viewer/2022051601/5abf20e97f8b9ab02d8dcb26/html5/thumbnails/24.jpg)
Order Processing
<service name=" orderProcessing " >
<inbound >
<inbound-endpoint address ="vm://processOrder" synchronous ="true" >
<expression-transformer >
<return-argument evaluator ="header" expression ="jersey.response" />
</ expression - transformer ></ expression - transformer >
<expression-transformer >
<return-argument evaluator ="groovy" expression ="payload.entity" />
</ expression-transformer >
</ inbound-endpoint >
</ inbound >
<outbound> … </outbound>
</service>
All contents Copyright 2008, MuleSource Inc. 24
![Page 25: Mule Enterprise to the Web - QCon San Francisco · Bringing the enterprise to the web with Mule. So RESTful ... Supports a variety of service topologies including ESB Highly ... –](https://reader034.fdocuments.in/reader034/viewer/2022051601/5abf20e97f8b9ab02d8dcb26/html5/thumbnails/25.jpg)
Order Processing
<service name="orderProcessing" >
<inbound >…</inbound >
<outbound >
<chaining-router >
<outbound-endpoint address ="vm://warehouseService" />
<!-- Post this to the AtomPub event log -->
<outbound-endpoint
address ="http://localhost:9002/atompub" ... >
</ chaining-router >
</ outbound >
</ service >
All contents Copyright 2008, MuleSource Inc. 25
![Page 26: Mule Enterprise to the Web - QCon San Francisco · Bringing the enterprise to the web with Mule. So RESTful ... Supports a variety of service topologies including ESB Highly ... –](https://reader034.fdocuments.in/reader034/viewer/2022051601/5abf20e97f8b9ab02d8dcb26/html5/thumbnails/26.jpg)
Warehousing
<service name=" warehouseService " >
<inbound >
<inbound-endpoint address ="vm://warehouseService" />
<inbound-endpoint
address =" jersey:http ://localhost:9002/warehouse" address =" jersey:http ://localhost:9002/warehouse"
synchronous ="true“ / >
</ inbound >
<component >
<singleton-object class =“…WarehouseService" />
</ component >
</ service >
All contents Copyright 2008, MuleSource Inc. 26
![Page 27: Mule Enterprise to the Web - QCon San Francisco · Bringing the enterprise to the web with Mule. So RESTful ... Supports a variety of service topologies including ESB Highly ... –](https://reader034.fdocuments.in/reader034/viewer/2022051601/5abf20e97f8b9ab02d8dcb26/html5/thumbnails/27.jpg)
Its just Java
public class WarehouseService {
public void requestParts (Order order ) {public void requestParts (Order order ) {
…
}
}
All contents Copyright 2008, MuleSource Inc. 27
![Page 28: Mule Enterprise to the Web - QCon San Francisco · Bringing the enterprise to the web with Mule. So RESTful ... Supports a variety of service topologies including ESB Highly ... –](https://reader034.fdocuments.in/reader034/viewer/2022051601/5abf20e97f8b9ab02d8dcb26/html5/thumbnails/28.jpg)
ATOMPUB
All contents Copyright 2008, MuleSource Inc. 28
![Page 29: Mule Enterprise to the Web - QCon San Francisco · Bringing the enterprise to the web with Mule. So RESTful ... Supports a variety of service topologies including ESB Highly ... –](https://reader034.fdocuments.in/reader034/viewer/2022051601/5abf20e97f8b9ab02d8dcb26/html5/thumbnails/29.jpg)
Consider using Atom Publishing Protocol
Atom: a format for syndication – Describes “lists of related information” – a.k.a. feeds
– Feeds are composed of entries
User Extensible
More generic than just blog stuff
![Page 30: Mule Enterprise to the Web - QCon San Francisco · Bringing the enterprise to the web with Mule. So RESTful ... Supports a variety of service topologies including ESB Highly ... –](https://reader034.fdocuments.in/reader034/viewer/2022051601/5abf20e97f8b9ab02d8dcb26/html5/thumbnails/30.jpg)
Atom Publishing Protocol
RESTful protocol for building servicesCreate, edit, delete entries in a collection Extensible Protocol– Paging extensions
Service
Workspaces– Paging extensions– GData– Opensearch
Properly uses HTTP so can be scalable, reliable and secure
CollectionsEntries
• Entry Resource
Media Entries• Media Link Entry• Media Resource
![Page 31: Mule Enterprise to the Web - QCon San Francisco · Bringing the enterprise to the web with Mule. So RESTful ... Supports a variety of service topologies including ESB Highly ... –](https://reader034.fdocuments.in/reader034/viewer/2022051601/5abf20e97f8b9ab02d8dcb26/html5/thumbnails/31.jpg)
Why you should use APP for your app
Provides ubiquitous elements which have meaning across all contexts
You can leverage existing solutions for security – HTTP Auth, WSSE, Google Login, XML Sig & Enc
Eliminates the need for you to write a lot of server/client code– ETags, URLs, etc are all handled for you
Integrates seamlessly with non-XML data
There are many APP implementations and they are known to work well together
![Page 32: Mule Enterprise to the Web - QCon San Francisco · Bringing the enterprise to the web with Mule. So RESTful ... Supports a variety of service topologies including ESB Highly ... –](https://reader034.fdocuments.in/reader034/viewer/2022051601/5abf20e97f8b9ab02d8dcb26/html5/thumbnails/32.jpg)
Eventing
Publish and consume entries which map to events
Application level events– Exceptions/fault monitoring
Business level eventsBusiness level events– A expense over $1000 was registered
Use query parameters to narrow down the criteria
Works with any client which understands Atom
Powerful combination with opensearch
![Page 33: Mule Enterprise to the Web - QCon San Francisco · Bringing the enterprise to the web with Mule. So RESTful ... Supports a variety of service topologies including ESB Highly ... –](https://reader034.fdocuments.in/reader034/viewer/2022051601/5abf20e97f8b9ab02d8dcb26/html5/thumbnails/33.jpg)
Process
Is order > Log to Order is placed Is order >
$10,000
Log to business event
Atom store
All contents Copyright 2008, MuleSource Inc. 33
![Page 34: Mule Enterprise to the Web - QCon San Francisco · Bringing the enterprise to the web with Mule. So RESTful ... Supports a variety of service topologies including ESB Highly ... –](https://reader034.fdocuments.in/reader034/viewer/2022051601/5abf20e97f8b9ab02d8dcb26/html5/thumbnails/34.jpg)
Abdera Concepts
AtomService
AbderaProvider
Workspace
Collection
WorkspaceManager
CollectionAdapter
All contents Copyright 2008, MuleSource Inc. 34
![Page 35: Mule Enterprise to the Web - QCon San Francisco · Bringing the enterprise to the web with Mule. So RESTful ... Supports a variety of service topologies including ESB Highly ... –](https://reader034.fdocuments.in/reader034/viewer/2022051601/5abf20e97f8b9ab02d8dcb26/html5/thumbnails/35.jpg)
CollectionAdapters
Write your own
Built in CollectionAdaptersBuilt in CollectionAdapters– JCR
– JDBC
– Filesystem
All contents Copyright 2008, MuleSource Inc. 35
![Page 36: Mule Enterprise to the Web - QCon San Francisco · Bringing the enterprise to the web with Mule. So RESTful ... Supports a variety of service topologies including ESB Highly ... –](https://reader034.fdocuments.in/reader034/viewer/2022051601/5abf20e97f8b9ab02d8dcb26/html5/thumbnails/36.jpg)
<mule:service name="customerService" >
<mule:inbound >
<mule:inbound - endpoint address ="http://localhost:9002" <mule:inbound - endpoint address ="http://localhost:9002"
remoteSync ="true" />
</ mule:inbound >
<abdera:component provider-ref =“abderaProvider" />
</ mule:service >
All contents Copyright 2008, MuleSource Inc. 36
![Page 37: Mule Enterprise to the Web - QCon San Francisco · Bringing the enterprise to the web with Mule. So RESTful ... Supports a variety of service topologies including ESB Highly ... –](https://reader034.fdocuments.in/reader034/viewer/2022051601/5abf20e97f8b9ab02d8dcb26/html5/thumbnails/37.jpg)
<a:provider id =“abderaProvider" >
<a:workspace title =“Event Workspace" ><a:workspace title =“Event Workspace" >
<ref bean =“jcrAdapter“/ >
</ a:workspace >
</ a:provider >
All contents Copyright 2008, MuleSource Inc. 37
![Page 38: Mule Enterprise to the Web - QCon San Francisco · Bringing the enterprise to the web with Mule. So RESTful ... Supports a variety of service topologies including ESB Highly ... –](https://reader034.fdocuments.in/reader034/viewer/2022051601/5abf20e97f8b9ab02d8dcb26/html5/thumbnails/38.jpg)
JCR Store
<bean id ="jcrAdapter"
class =“…abdera.protocol.server.adapters.jcr.JcrCollection Adapter"
init-method ="initialize" >
<property name="author" value ="Mule" />
<property name="title" value ="Event Queue" />
<property name="collectionNodePath" value ="entries" />
<property name="repository" ref =" jcrRepository " /><property name="repository" ref =" jcrRepository " />
<property name="credentials" >
<bean class ="javax.jcr.SimpleCredentials" >
<constructor-arg ><value >username </ value ></ constructor-arg >
<constructor-arg ><value >password </ value ></ constructor-arg >
</ bean >
</ property >
<property name="href" value ="events" />
</ bean >
All contents Copyright 2008, MuleSource Inc. 38
![Page 39: Mule Enterprise to the Web - QCon San Francisco · Bringing the enterprise to the web with Mule. So RESTful ... Supports a variety of service topologies including ESB Highly ... –](https://reader034.fdocuments.in/reader034/viewer/2022051601/5abf20e97f8b9ab02d8dcb26/html5/thumbnails/39.jpg)
Creating Atom Entries
<!-- Post this to the AtomPub event log -->
<outbound-endpoint address ="http://localhost:9002/atompub" >
<expression-filter evaluator ="groovy"
expression ="payload.price > 10000" />
<message-properties-transformer >
<add-message-property key ="Content-Type"
value ="application/atom+xml;type=entry" />
<delete-message-property key ="http.custom.headers" />
</ message-properties-transformer >
<custom-transformer
class ="org.mule.examples.mfg.util.EntryTransformer" />
<custom-transformer
class ="org.mule.transport.abdera.BaseToOutputHandler" />
</ outbound-endpoint >
All contents Copyright 2008, MuleSource Inc. 39
![Page 40: Mule Enterprise to the Web - QCon San Francisco · Bringing the enterprise to the web with Mule. So RESTful ... Supports a variety of service topologies including ESB Highly ... –](https://reader034.fdocuments.in/reader034/viewer/2022051601/5abf20e97f8b9ab02d8dcb26/html5/thumbnails/40.jpg)
Transformers
public class EntryTransformer extends
AbstractTransformer {
@Override
protected Object doTransform (protected Object doTransform (
Object src, String encoding)
throws TransformerException {
…
}
}
All contents Copyright 2008, MuleSource Inc. 40
![Page 41: Mule Enterprise to the Web - QCon San Francisco · Bringing the enterprise to the web with Mule. So RESTful ... Supports a variety of service topologies including ESB Highly ... –](https://reader034.fdocuments.in/reader034/viewer/2022051601/5abf20e97f8b9ab02d8dcb26/html5/thumbnails/41.jpg)
Transformers
Order order = (Order) src;
Entry entry = factory .newEntry();
entry.setTitle( "Order for " + order.getPrice() +
" from " + order.getCustomer());
entry.setId ( factory .newUuidUri ());entry.setId ( factory .newUuidUri ());
entry.setContent( "An order was placed for " +
order.getPrice() + " from " +
order.getCustomer());
entry.setUpdated( new Date());
entry.addAuthor( "Mule Mfg Company" );
return entry;
All contents Copyright 2008, MuleSource Inc. 41
![Page 42: Mule Enterprise to the Web - QCon San Francisco · Bringing the enterprise to the web with Mule. So RESTful ... Supports a variety of service topologies including ESB Highly ... –](https://reader034.fdocuments.in/reader034/viewer/2022051601/5abf20e97f8b9ab02d8dcb26/html5/thumbnails/42.jpg)
POLLING VS. MESSAGING
All contents Copyright 2008, MuleSource Inc. 42
![Page 43: Mule Enterprise to the Web - QCon San Francisco · Bringing the enterprise to the web with Mule. So RESTful ... Supports a variety of service topologies including ESB Highly ... –](https://reader034.fdocuments.in/reader034/viewer/2022051601/5abf20e97f8b9ab02d8dcb26/html5/thumbnails/43.jpg)
ETag Header
Resources may return an ETag header when it is accessed
On subsequent retrieval of the resource, Client sends this ETag header backheader back
If the resource has not changed (i.e. the ETag is the same), an empty response with a 304 code is returned
Reduces bandwidth/latency
![Page 44: Mule Enterprise to the Web - QCon San Francisco · Bringing the enterprise to the web with Mule. So RESTful ... Supports a variety of service topologies including ESB Highly ... –](https://reader034.fdocuments.in/reader034/viewer/2022051601/5abf20e97f8b9ab02d8dcb26/html5/thumbnails/44.jpg)
Client Server
ETag Example
HTTP/1.1 200 OK
Date: …
ETag: "3e86-410-3596fbbc"
Content-Length: 1040
Content-Type: text/html
…
GET /feed.atomHost: www.acme.com…
ServerClient
HTTP/1.1 304 Not ModifiedDate: …ETag: "3e86-410-3596fbbc" Content-Length: 0…
GET /feed.atomIf-None-Match:
"3e86-410-3596fbbc"Host: www.acme.com…
![Page 45: Mule Enterprise to the Web - QCon San Francisco · Bringing the enterprise to the web with Mule. So RESTful ... Supports a variety of service topologies including ESB Highly ... –](https://reader034.fdocuments.in/reader034/viewer/2022051601/5abf20e97f8b9ab02d8dcb26/html5/thumbnails/45.jpg)
LastModified Example
HTTP/1.1 200 OK
Date: …
Last-Modified: Sat, 29 Oct
1994 19:43:31 GMT
Content-Length: 1040
GET /feed.atomHost: www.acme.com…
Client Server
Content-Type: text/html
…
HTTP/1.1 304 Not ModifiedDate: …Last-Modified: Sat, 29 Oct
1994 19:43:31 GMTContent-Length: 0
GET /feed.atomIf-Modified-Since:
Sat, 29 Oct 1994 19:43:31 GMT
Host: www.acme.com…
![Page 46: Mule Enterprise to the Web - QCon San Francisco · Bringing the enterprise to the web with Mule. So RESTful ... Supports a variety of service topologies including ESB Highly ... –](https://reader034.fdocuments.in/reader034/viewer/2022051601/5abf20e97f8b9ab02d8dcb26/html5/thumbnails/46.jpg)
Process
Poll Have the Poll warehouse for part updates
Have the parts arrived? Update status
All contents Copyright 2008, MuleSource Inc. 46
![Page 47: Mule Enterprise to the Web - QCon San Francisco · Bringing the enterprise to the web with Mule. So RESTful ... Supports a variety of service topologies including ESB Highly ... –](https://reader034.fdocuments.in/reader034/viewer/2022051601/5abf20e97f8b9ab02d8dcb26/html5/thumbnails/47.jpg)
Wiring with XML
<http:polling-connector
name="PollingHttpConnector"
pollingFrequency ="30000"
checkEtag ="true" />
<service name=" eventConsumer " >
<inbound >
<inbound-endpoint
address ="http://localhost:9002/warehouse"
connector-ref ="PollingHttpConnector" />
</ inbound >
</service>
All contents Copyright 2008, MuleSource Inc. 47
![Page 48: Mule Enterprise to the Web - QCon San Francisco · Bringing the enterprise to the web with Mule. So RESTful ... Supports a variety of service topologies including ESB Highly ... –](https://reader034.fdocuments.in/reader034/viewer/2022051601/5abf20e97f8b9ab02d8dcb26/html5/thumbnails/48.jpg)
Is polling the answer?
Example from OSCON:
“On July 21st, 2008, friendfeed crawled flickr 2.9 million times to get the latest photos of 45,754 users, of which 6,721 of that 45,754 potentially uploaded a photo.”
![Page 49: Mule Enterprise to the Web - QCon San Francisco · Bringing the enterprise to the web with Mule. So RESTful ... Supports a variety of service topologies including ESB Highly ... –](https://reader034.fdocuments.in/reader034/viewer/2022051601/5abf20e97f8b9ab02d8dcb26/html5/thumbnails/49.jpg)
Frequent updates are common
Flickr
Blogs
TwitterTwitter
Business events
Presence on IM
Stock data
![Page 50: Mule Enterprise to the Web - QCon San Francisco · Bringing the enterprise to the web with Mule. So RESTful ... Supports a variety of service topologies including ESB Highly ... –](https://reader034.fdocuments.in/reader034/viewer/2022051601/5abf20e97f8b9ab02d8dcb26/html5/thumbnails/50.jpg)
Is messaging the answer?
Messaging is asynchronous Messaging is asynchronous
Doesn’t put undue load on the server and the client
![Page 51: Mule Enterprise to the Web - QCon San Francisco · Bringing the enterprise to the web with Mule. So RESTful ... Supports a variety of service topologies including ESB Highly ... –](https://reader034.fdocuments.in/reader034/viewer/2022051601/5abf20e97f8b9ab02d8dcb26/html5/thumbnails/51.jpg)
Roy’s Solution for Flickr/Friendfeed
![Page 52: Mule Enterprise to the Web - QCon San Francisco · Bringing the enterprise to the web with Mule. So RESTful ... Supports a variety of service topologies including ESB Highly ... –](https://reader034.fdocuments.in/reader034/viewer/2022051601/5abf20e97f8b9ab02d8dcb26/html5/thumbnails/52.jpg)
Lookup service
http://example.com/_2008/09/03/users?{userid}http://example.com/_2008/09/03/users?{userid}
Returns coordinate in sparse array
![Page 53: Mule Enterprise to the Web - QCon San Francisco · Bringing the enterprise to the web with Mule. So RESTful ... Supports a variety of service topologies including ESB Highly ... –](https://reader034.fdocuments.in/reader034/viewer/2022051601/5abf20e97f8b9ab02d8dcb26/html5/thumbnails/53.jpg)
Leaves us with
Periodic poll (every minute or so) with a 1KB response (1440 times/day)times/day)
6700 GETs for new pictures
A GET for every time a user signs up
![Page 54: Mule Enterprise to the Web - QCon San Francisco · Bringing the enterprise to the web with Mule. So RESTful ... Supports a variety of service topologies including ESB Highly ... –](https://reader034.fdocuments.in/reader034/viewer/2022051601/5abf20e97f8b9ab02d8dcb26/html5/thumbnails/54.jpg)
In contrast to
6700 XMPP messages per day
6700 GETs for new pictures
Maintenance of new infrastructure
![Page 55: Mule Enterprise to the Web - QCon San Francisco · Bringing the enterprise to the web with Mule. So RESTful ... Supports a variety of service topologies including ESB Highly ... –](https://reader034.fdocuments.in/reader034/viewer/2022051601/5abf20e97f8b9ab02d8dcb26/html5/thumbnails/55.jpg)
Questions?
http://mulesource.com
http://mule.mulesource.org/display/MULE/MULE+RESTpack
My Blog: http://netzooid.com/blogMy Blog: http://netzooid.com/blog
All contents Copyright 2008, MuleSource Inc. 55