lightweight restful integration with mule€¦ · why do developers choose mule? no prescribed...

Post on 24-Aug-2020

1 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

the open source choice for SOA infrastructure

Lightweight RESTful Integration with

MuleDan Diephouse

All contents Copyright ! 2008, MuleSource Inc. 2

SOA defined

All contents Copyright ! 2008, MuleSource Inc. 3

SOA is dead?

Website

Service

Application

Library

All contents Copyright ! 2008, MuleSource Inc. 4

Crap to deal with when building services

Versioning

Coupling

Interoperability

Scalability

Infrastructure

All contents Copyright ! 2008, MuleSource Inc. 5

REST: Loosely coupled

All contents Copyright ! 2008, MuleSource Inc. 6

REST: Interoperability

All contents Copyright ! 2008, MuleSource Inc. 7

REST: Scalability

All contents Copyright ! 2008, MuleSource Inc. 8

!"#$%!&'()#*+,-./+*#0,+#/"")12

All contents Copyright ! 2008, MuleSource Inc. 9

The magical mystery bus!

All contents Copyright ! 2008, MuleSource Inc. 10

ESB

Routing

Transform-ations

Messaging

Queueing

Security

Transactions

All contents Copyright ! 2008, MuleSource Inc. 11

Why do developers choose Mule?

No prescribed message format3 XML, CSV, Binary, Streams, Record, Java Objects3 Mix and match

Zero code intrusion3 Mule does not impose an API on service objects3 Objects are fully portable

Existing objects can be managed3 POJOs, IoC Objects, EJB Session Beans, Remote Objects3 REST & Web Services

Easy to test3 Mule can be run easily from a JUnit test case3 Framework provides a Test compatibility kit3 Scales down as well as up

Mule Manufacturing Co.

All contents Copyright ! 2008, MuleSource Inc. 13

Service

Mule Services

All contents Copyright ! 2008, MuleSource Inc. 14

ComponentInbound

Endpoints

Outbound Routers

Core Concepts: Connectors

HTTP

JMS

FTP

TCP

UDP

LDAP

BPM

CXF

File

POP

SMTP

Multicast

VM

XMPP

WSDL

STDIO

All contents Copyright ! 2008, MuleSource Inc. 15

Core Concepts: Endpoints

Used to connect components and external systems together

Endpoints use a URI for Addressing

Can have transformer, transaction, filter, security and meta-information associated

Two types of URI

3 scheme://[username][:password]@[host][:port]

?[params]! smtp://ross:pass@localhost:25

3 scheme://[address]?[params]! jms://my.queue?persistent=true

Core Concepts: Routers

Control how events are sent and receivedCan model all routing patterns defined in the EIP BookInbound Routers3 Idempotency3 Selective Consumers3 Re-sequencing3 Message aggregation

Outbound Routers3 Message splitting / Chunking3 Content-based Routing3 Broadcasting3 Rules-based routing3 Load Balancing

Core Concepts: Transformers

Transformers3 Converts data from one format to another3 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"/>

Simple example

!"#$%&'#()*+#,-.#/0#$%&'#"-1

!&)/23)41

!&)/23)45#)462&)7(*44$#"",-87769::;2'*;82"79<=>?>-(((((((((((

"@)'8$2)23",-7$3#-(:1

!:&)/23)41

!237/23)41

!6*""578$23A85$237#$1

!237/23)45#)462&)7(*44$#"",-%+9::2$4#$B3#3#-:1

!:6*""578$23A85$237#$1

!:237/23)41

!:"#$%&'#1

All contents Copyright ! 2008, MuleSource Inc. 19

Simple example

!"#$%&'#()*+#,-.#/0#$%&'#"-1

!&)/23)41

!&)/23)45#)462&)7(*44$#"",!"#$%%&'()'*+)+),-----------

"@)'8$2)23",-7$3#-(

7$*)"C2$+#$5$#C",!D"%E2F$4#$G2H2!:1

!:&)/23)41

!'2+62)#)7(';*"",!.I@F$4#$0#$%&'#!%1

!:"#$%&'#1

All contents Copyright ! 2008, MuleSource Inc. 20

BUILDING SERVICES

All contents Copyright ! 2008, MuleSource Inc. 21

Jersey

Annotations to expose your classes as a RESTful service

Implements the JAX-RS (JSR311) specification

Mule connector makes it possible to embed JAX-RS services in

Mule

All contents Copyright ! 2008, MuleSource Inc. 22

JG*78K-:8#;;2.2$;4-L

63/;&' ';*"" M#;;2N2$;4O#"23$'# P

JQRE

JG$243'#I&+#K-7#S7:6;*&)-L

63/;&' 07$&)A("*@M#;;2N2$;4KL(P

$#73$) -M#;;2(N2$;4-T

U

U

All contents Copyright ! 2008, MuleSource Inc. 23

JGF0E

JG$243'#"K-*66;&'*7&2):S+;-L(((

JD2)"3+#"K-*66;&'*7&2):S+;-L

63/;&' O#"62)"#(6;*'#F$4#$KF$4#$(2$4#$L(P

&)7 )3+/#$(,(A#7V#S7F$4#$V3+/#$KLT

.

WOX(;2'*7&2)(,(3$&X)C2YA#7Z/"2;37#G*78KL

Y$#"2;%#K-:2$4#$":- [()3+/#$LT

$#73$) O#"62)"#Y!"#$%#&'()!$%*)+,

Y#)7&7@K2$4#$L

Y/3&;4KLT

U

All contents Copyright ! 2008, MuleSource Inc. 24

JQRE

JG$243'#"K-*66;&'*7&2):S+;-L

JG*78K-:P&4U-L

63/;&' F$4#$(A#7F$4#$KJG*78G*$*+K-&4-L(&)7 &4L(P

$#73$) 2$4#$"YA#7K&4LT

U

All contents Copyright ! 2008, MuleSource Inc. 25

Simple Service Configuration

!"#$%&'#()*+#,!2$4#$O#"23$'#-1

!&)/23)41

!&)/23)45#)462&)7(

*44$#"",-H#$"#@987769::;2'*;82"79<=>?\:2$4#$"-:1

!:&)/23)41

!'2+62)#)7(

';*"",-2$AY+3;#Y#S*+6;#"Y+CAYF$4#$O#"23$'#-:1

!:"#$%&'#1

All contents Copyright ! 2008, MuleSource Inc. 26

Why Jersey?

Very easy to build RESTful services inside Mule

Built in serialization support for

3 XML via JAXB

3 JSON

3 Images

3 Easily write your own serializers

All contents Copyright ! 2008, MuleSource Inc. 27

INTEGRATING REST INTO YOUR MESSAGING LAYER

All contents Copyright ! 2008, MuleSource Inc. 28

Process flow

All contents Copyright ! 2008, MuleSource Inc. 29

Order

Resource

POST

Order

HTTP

responseInternal order

processing queue

!"#$%&'#1

.

!]55 X"(78&"(*()#.(2$4#$^(XC("2_(&)&7&*7#(78#(/*'`#)4(

6$2'#""&)A(551

!C&;7#$&)A5$237#$1

!237/23)45#)462&)7(*44$#"",-./0112")!#334"&#"-15

!*)45C&;7#$1

!$#"7;#793$&57#+6;*7#5C&;7#$(

%#$/",-6478-92$%%#"+:-1)"&#"3-15

!#S6$#""&2)5C&;7#$(

#%*;3*72$,-;#$&#"-9#<2"#33*)+:-;%%2=3%$%>3:?@A-915

!:*)45C&;7#$1

!:C&;7#$&)A5$237#$1

!:"#$%&'#1

All contents Copyright ! 2008, MuleSource Inc. 30

Another example: URI template routing

!"#$%&'#()*+#,-.#/0#$%&'#"-1

!&)/23)41

!&)/23)45#)462&)7(*44$#"",-87769::;2'*;82"79<=>?>-(((((((((((

"@)'8$2)23",-7$3#-(:1

!:&)/23)41

!237/23)41

!C&;7#$&)A5$237#$1

!237/23)45#)462&)7(*44$#"",-%+9::2$4#$B3#3#-:1

!$#"7;#793$&57#+6;*7#5C&;7#$(6*77#$),-:2$4#$":P2$4#$X4U-:1

!:C&;7#$&)A5$237#$1

!C&;7#$&)A5$237#$1

!237/23)45#)462&)7(*44$#"",-%+9::3"#$B3#3#-:1

!$#"7;#793$&57#+6;*7#5C&;7#$(6*77#$),-:3"#$"-(:1

!:C&;7#$&)A5$237#$1

!:237/23)41

!:"#$%&'#1

All contents Copyright ! 2008, MuleSource Inc. 31

Modify messages while filtering!

!$#"7;#793$&57#+6;*7#5C&;7#$(

6*77#$),-:2$4#$X4:P"#758#*4#$Y2$4#$X4U-(:1

!$#"7;#793$&57#+6;*7#5C&;7#$(

6*77#$),-:2$4#$X4:P"#756*@;2*4Y2$4#$X4U-(:1

All contents Copyright ! 2008, MuleSource Inc. 32

Order Processing

All contents Copyright ! 2008, MuleSource Inc. 33

Order processing

queue

Warehouse availability

check

Log business events

Order Processing

!"#$%&'#()*+#,-)"&#"6")!#33*+B-5

!&)/23)41

!&)/23)45#)462&)7(*44$#"",-./0112")!#334"&#"-93C+!;")+)>3:-%">#-5

!#S6$#""&2)57$*)"C2$+#$1

!$#73$)5*$A3+#)7(#%*;3*72$,-;#$&#"-9#<2"#33*)+:-D#"3#C="#32)+3#-915

!:#S6$#""&2)57$*)"C2$+#$1

!#S6$#""&2)57$*)"C2$+#$1

!$#73$)5*$A3+#)7(#%*;3*72$,-B")).C-9#<2"#33*)+:-2$C()$&=#+%*%C-915

!:#S6$#""&2)57$*)"C2$+#$1

!:&)/23)45#)462&)71

!:&)/23)41(

/&+01&+2(3-.-/%&+01&+2(3

!:"#$%&'#1

All contents Copyright ! 2008, MuleSource Inc. 34

Order Processing

!"#$%&'#()*+#,-)"&#"6")!#33*+B-5

!&)/23)43./%&)/23)41

!237/23)41

!'8*&)&)A5$237#$1

!237/23)45#)462&)7(*44$#"",-./011E$"#;)>3#7#".*!#-15

!]55 G2"7(78&"(72(78#(Z72+G3/ #%#)7(;2A(551

!237/23)45#)462&)7

*44$#"",-;%%2011()!$(;)3%0F@@?1$%)/2>G-9===95

!:'8*&)&)A5$237#$1

!:237/23)41

!:"#$%&'#1

All contents Copyright ! 2008, MuleSource Inc. 35

Warehousing

!"#$%&'#()*+#,-E$"#;)>3#7#".*!#-5

!&)/23)41

!&)/23)45#)462&)7(*44$#"",-./011E$"#;)>3#7#".*!#-15

!&)/23)45#)462&)7(

*44$#"",-D#"3#C0;%%2011()!$(;)3%0F@@?1E$"#;)>3#-9

3C+!;")+)>3:!"#$%&11

!:&)/23)41

!'2+62)#)71

!"&)A;#72)52/H#'7(';*"",&'H$"#;)>3#7#".*!#-15

!:'2+62)#)71

!:"#$%&'#1

All contents Copyright ! 2008, MuleSource Inc. 36

Its just Java

63/;&' ';*"" N*$#823"#0#$%&'# P

63/;&' %2&4 $#a3#"7G*$7"KF$4#$(2$4#$L(P

.

U

U

All contents Copyright ! 2008, MuleSource Inc. 37

ATOMPUB

All contents Copyright ! 2008, MuleSource Inc. 38

Consider using Atom Publishing Protocol

Atom: a format for syndication

3 4+*/,.5+*#6).*7*#"'#,+)07+8#.9'",:07."9;#3 a.k.a. feeds

3 Feeds are composed of entries

User Extensible

More generic than just blog stuff

Atom Publishing Protocol

RESTful protocol for building services

Create, edit, delete entries in a collection

Extensible Protocol

3 Paging extensions

3 GData

3 Opensearch

Properly uses HTTP so can be scalable, reliable and secure

Service

Workspaces

CollectionsEntries

< Entry Resource

Media Entries

< Media Link Entry< Media Resource

Why you should use APP for your app

Provides ubiquitous elements which have meaning across all

contexts

You can leverage existing solutions for security

3 HTTP Auth, WSSE, Google Login, XML Sig & Enc

Eliminates the need for you to write a lot of server/client code

3 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

Eventing

Publish and consume entries which map to events

Application level events

3 Exceptions/fault monitoring

Business level events

3 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

Process

Order is placedIs order > $10,000

Log to business event

Atom store

All contents Copyright ! 2008, MuleSource Inc. 43

Abdera Concepts

Atom

Service

Workspace

Collection

Abdera

Provider

WorkspaceManager

CollectionAdapter

All contents Copyright ! 2008, MuleSource Inc. 44

CollectionAdapters

Write your own

Built in CollectionAdapters

3 JCR

3 JDBC

3 Filesystem

All contents Copyright ! 2008, MuleSource Inc. 45

!+3;#9"#$%&'# )*+#,-'3"72+#$0#$%&'#-1

!+3;#9&)/23)41

!+3;#9&)/23)45#)462&)7(*44$#"",-87769::;2'*;82"79b>>c-(

"@)'8$2)23",-7$3#-:1

!:+3;#9&)/23)41

!*/4#$*9'2+62)#)7 6$2%&4#$5$#C,!*/4#$*G$2%&4#$-:1

!:+3;#9"#$%&'#1

All contents Copyright ! 2008, MuleSource Inc. 46

!*96$2%&4#$(&4,!*/4#$*G$2%&4#$-1

!*9.2$`"6*'#(7&7;#,!4")20-5&'6789:),1

!$#C(/#*),!H'$Z4*67#$!%1

!:*9.2$`"6*'#1

!:*96$2%&4#$1

All contents Copyright ! 2008, MuleSource Inc. 47

JCR Store

!/#*)(&4,-D!"I&$2%#"-9

';*"",&'$G&#"$=2")%)!)(=3#".#"=$&$2%#"3=D!"=J!"K)((#!%*)+I&$2%#"-9

*+*%L/#%;)&:-*+*%*$(*M#-5

!6$26#$7@()*+#,-$>%;)"-9.$(>#:-N>(#-15

!6$26#$7@()*+#,-%*%(#-9.$(>#:-O.#+%9P>#>#-15

!6$26#$7@()*+#,-!)((#!%*)+Q)&#6$%;-9.$(>#:-#+%"*#3-15

!6$26#$7@()*+#,-"#2)3*%)"C-9"#R:-D!"S#2)3*%)"C-15

!6$26#$7@()*+#,-!"#&#+%*$(3-5

!/#*)(';*"",-D$.$<=D!"=7*/2(#K"#&#+%*$(3-5

!'2)"7$3'72$5*$A1!%*;3#13"#$)*+#!:%*;3#1!:'2)"7$3'72$5*$A1

!'2)"7$3'72$5*$A1!%*;3#16*"".2$4!:%*;3#1!:'2)"7$3'72$5*$A1

!:/#*)1

!:6$26#$7@1

!6$26#$7@()*+#,-;"#R-9.$(>#:-#.#+%3-15

!:/#*)1

All contents Copyright ! 2008, MuleSource Inc. 48

Creating Atom Entries

!]55 G2"7(78&"(72(78#(Z72+G3/ #%#)7(;2A(551

!237/23)45#)462&)7(*44$#"",-;%%2011()!$(;)3%0F@@?1$%)/2>G-5

!#S6$#""&2)5C&;7#$(#%*;3*72$,-B")).C-9

#<2"#33*)+:-2$C()$&=2"*!# 59A@@@@-15

!+#""*A#56$26#$7&#"57$*)"C2$+#$(1

!*445+#""*A#56$26#$7@(`#@,-K)+%#+%L8C2#-9

.$(>#:-$22(*!$%*)+1$%)/T</(U%C2#:#+%"C-15

!:+#""*A#56$26#$7&#"57$*)"C2$+#$1

!*/4#$*9#)7$@50'927;&'#)'-.3

!:237/23)45#)462&)71

All contents Copyright ! 2008, MuleSource Inc. 49

Transformers

63/;&' ';*"" R)7$@E$*)"C2$+#$ #S7#)4"

Z/"7$*'7E$*)"C2$+#$ P

JF%#$$&4#

6$27#'7#4 F/H#'7(42E$*)"C2$+K

F/H#'7("$'_(07$&)A(#)'24&)AL(

78$2." E$*)"C2$+#$RS'#67&2) P

.

U

U

All contents Copyright ! 2008, MuleSource Inc. 50

Transformers

F$4#$(2$4#$ ,(KF$4#$L("$'T

R)7$@(#)7$@ ,(C*'72$@Y)#.R)7$@KLT

#)7$@Y"#7E&7;#K-F$4#$(C2$(- [(2$4#$YA#7G$&'#KL([(

-(C$2+(- [(2$4#$YA#7D3"72+#$KLLT

#)7$@Y"#7X4KC*'72$@Y)#.W3&4W$&KLLT

#)7$@Y"#7D2)7#)7K-Z)(2$4#$(.*"(6;*'#4(C2$(- [(

2$4#$YA#7G$&'#KL([(-(C$2+(- [(

2$4#$YA#7D3"72+#$KLLT

#)7$@Y"#7W64*7#4K)#. d*7#KLLT

#)7$@Y*44Z3782$K-I3;#(ICA(D2+6*)@-LT

$#73$) #)7$@T

All contents Copyright ! 2008, MuleSource Inc. 51

XML version

!*/4#$*9#)7$@5/3&;4#$57$*)"C2$+#$1

!*/4#$*9#)7$@56$26#$7@()*+#,-$>%;)"-9

#.$(>$%)":-3%"*+B-9#<2"#33*)+:-S)339N$3)+-15

!*/4#$*9#)7$@56$26#$7@()*+#,-!)+%#+%-9

#.$(>$%)":-2$C()$&-9#<2"#33*)+:--15

!*/4#$*9#)7$@56$26#$7@()*+#,-%*%(#-9

#.$(>$%)":-;#$&#"-9#<2"#33*)+:-%*%(#-15

!*/4#$*9#)7$@56$26#$7@()*+#,->2&$%#&-9

#.$(>$%)":-R>+!%*)+-9#<2"#33*)+:-+)E-15

!*/4#$*9#)7$@56$26#$7@()*+#,-*&-999

#.$(>$%)":-B")).C-9

#<2"#33*)+:-V>"+0>>*&0V9T9

D$.$=>%*(=WWXY="$+&)/WWXY',=%)7%"*+B',-15

!:*/4#$*9#)7$@5/3&;4#$57$*)"C2$+#$1

All contents Copyright ! 2008, MuleSource Inc. 52

POLLING VS. MESSAGING

All contents Copyright ! 2008, MuleSource Inc. 53

ETag Header

Resources may return an ETag header when it is accessed

On subsequent retrieval of the resource, Client sends this ETag

header 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

ServerClient

Client Server

ETag Example

MEEG:\Y\(c>>(Fe(

<90)$-.

RE*A9(-=#?<5f\>5=gb<C//'-

D2)7#)75h#)A789(\>f>(

D2)7#)75E@6#9(7#S7:87+;

.

MEEG:\Y\(=>f(V27(I24&C&#4

<90)$-.

RE*A9(-=#?<5f\>5=gb<C//'-(

D2)7#)75=)2>0?$-@.

QRE(:C##4Y*72+

M2"79(...Y*'+#Y'2+

.

QRE(:C##4Y*72+

XC5V2)#5I*7'89(

-=#?<5f\>5=gb<C//'-

M2"79(...Y*'+#Y'2+

.

Client Server

LastModified Example

MEEG:\Y\(c>>(Fe(

<90)$-.

h*"75I24&C&#49(0*7_(cb(F'7(

\bbf(\b9f=9=\(QIE

D2)7#)75h#)A789(\>f>(

D2)7#)75E@6#9(7#S7:87+;

.

MEEG:\Y\(=>f(V27(I24&C&#4

<90)$-.

h*"75I24&C&#49(0*7_(cb(F'7(

\bbf(\b9f=9=\(QIE

D2)7#)75h#)A789(>

QRE(:C##4Y*72+

M2"79(...Y*'+#Y'2+

.

QRE(:C##4Y*72+

XC5I24&C&#450&)'#9(

0*7_(cb(F'7(\bbf(

\b9f=9=\(QIE

M2"79(...Y*'+#Y'2+

.

Process

Poll warehouse for part updates

Have the parts arrived?

Update status

All contents Copyright ! 2008, MuleSource Inc. 57

Wiring with XML

!8776962;;&)A5'2))#'72$(

)*+#,-6)((*+BZ%%2K)++#!%)"-9

62;;&)Ai$#a3#)'@,-[@@@@-9

!;#!\O%$B:-%">#-15

!"#$%&'#()*+#,-#.#+%K)+3>/#"-5

!&)/23)41

!&)/23)45#)462&)7(

*44$#"",-;%%2011()!$(;)3%0F@@?1E$"#;)>3#-9

!)++#!%)"L"#R:-6)((*+BZ%%2K)++#!%)"-15

!:&)/23)41

!:"#$%&'#1

All contents Copyright ! 2008, MuleSource Inc. 58

Is polling the answer?

Example from OSCON:

6=9#>()?#@A*7B#@CCDB#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 (E)"08+8#0#EF"7"2;

Frequent updates are common

Flickr

Blogs

Twitter

Business events

Presence on IM

Stock data

Is messaging the answer?

Messaging is asynchronous

4"+*9G7#E(7#(98(+#)"08#"9#7F+#*+,-+,#098#7F+#/).+97

!"#$%&'"()*+",&-".&Flickr/Friendfeed

Lookup service

http://example.com/_2008/09/03/users?{userid}

Returns coordinate in sparse array

Leaves us with

Periodic poll (every minute or so) with a 1KB response (1440

times/day)

6700 GETs for new pictures

A GET for every time a user signs up

In contrast to

6700 XMPP messages per day

6700 GETs for new pictures

Maintenance of new infrastructure

Conclusions

Services are hard!

In the long run, REST helps you

Getting away from the edges, Mule can help

Abdera, Jersey and Restlet are cool

Mule has a bunch of other tools to help you too

All contents Copyright ! 2008, MuleSource Inc. 66

Questions?

http://mulesource.com

http://mule.mulesource.org/display/MULE/MULE+RESTpack

My Blog: http://netzooid.com/blog

Twitter: dandiep

dan@netzooid.com

All contents Copyright ! 2008, MuleSource Inc. 67

top related