Professional Documents
Culture Documents
Enterprise Integration With Spring Integration: Agim Emruli Springsource 8100
Enterprise Integration With Spring Integration: Agim Emruli Springsource 8100
Agim Emruli
SpringSource
8100
2
Presentation Goal
Integration
Challenges
System Failures 4
5
Intolerant
Systems
6
Enterprise
Integration
Patterns
Pattern Catalog Overview 7
Command
Message Content FIlter Normalizer
Return Composed Splitter
Address Message
D
A B
Document
Message Content Process
Correlation ID Claim Check Aggregator
Enricher Manager
Event
Message Message Message Recipient List
Sequence FIlter
8
Aspect Enterprise
Dependency
oriented Service
Injection
Programming Abstraction
Inversion of Control
10
Focus on
Business
domain
11
Testable Robust
Application
Maintain-
Flexible
able
Layered Architecture 12
Layered Architecture 12
Domain
Objects
Layered Architecture 12
Domain
Objects
Domain
Objects
Infrastructure
Domain
Data Access Objects
Infrastructure
Services
Domain
Data Access Objects
Infrastructure
AOP Services
Domain
Data Access Objects
Infrastructure
Layered Architecture
Spring Application
13
Layered Architecture
MVC
Spring Application
13
Layered Architecture
MVC RMI
Spring Application
13
Layered Architecture
Spring Application
13
Layered Architecture
Batch
Spring Application
13
Layered Architecture
Batch JMS
Spring Application
14
Framework
Event Application
15
<jms:listener-container transaction-manager="txManager">
<jms:listener ref="orderService"
method="order"
destination="queue.orders"
response-destination="queue.confirmation"/>
</jms:listener-container>
15
}
16
Introducing
Spring
Integration
17
Goals
18
Reuse
Service
Layer
19
Incremental
Extension
20
Services
20
Services
20
Services
20
Services
20
Transformer
Services
20
Transformer
Router
Services
21
Message
Construction
22
Message Structure
Message Header
Sequence Number
Sequence Size
Expiration Date
Correlation Identifier
Message Body
C D E
Message Interface
MessageHeaders getHeaders();
T getPayload();
}
Message Headers 24
Message Headers 24
String value =
headers.get("key", String.class);
Object id = headers.getId();
MessagePriority priority =
headers.getPriority();
Message Builder 25
Message Builder 25
Message<String> message =
MessageBuilder.withPayload("test")
.setHeader("foo", 123)
.setPriority(MessagePriority.HIGHEST)
.build();
Message<String> copy =
MessageBuilder.fromMessage(message)
.setHeader("foo", 456)
.setHeaderIfAbsent("bar", 789)
.build();
Channels
26
And
Endpoints
27
Message Channel
Message Message
Direct Channels
Event-Driven
Message Endpoint Channel
Consumer
28
Direct Channels
Event-Driven
Message Endpoint Channel
Consumer
Queue Channel
Polling
Message Endpoint Channel
Consumer
29
Queue Channel
Polling
Message Endpoint Channel
Consumer
<channel id="async-p2p">
<queue capacity="50" />
</channel>
30
Publish-Subscribe Channel
Event-Driven
Consumer
Publish Subscribe
Message Endpoint
Channel
Event-Driven
Consumer
30
Publish-Subscribe Channel
Event-Driven
Consumer
Publish Subscribe
Message Endpoint
Channel
Event-Driven
Consumer
<publish-subscribe-channel
id="pubsub" />
31
Priority Channel
Polling
Message Endpoint Channel
Consumer
Resequencer
31
Priority Channel
Polling
Message Endpoint Channel
Consumer
Resequencer
<channel id="priorityChannel">
<priority-queue comparator="someComp" />
</channel>
Message 32
Transformation
33
Message Translator
Message Translator
<transformer input-channel="input"
output-channel="output" ref="transformer"
method="transform"/>
34
@MessageEndpoint
public class MessageTransformer{
@Transformer(inputChannel="in",
outputChannel="out")
public LoanRequest transform(Loan loan){
return ...;
}
}
Service Activator 35
36
Service Activator
Service Activator
Service Activator
<channel id="requests"/>
<channel id="quotes"/>
<service-activator input-channel="requests"
ref="loanBroker"
method="processRequest"
output-channel="quotes"/>
<beans:bean id="loanBroker"
class="example.LoanBroker"/>
38
@ServiceActivator(inputChannel="x",
outputChannel="y")
public LoanQuote processRequest(
LoanRequest request) {
LoanQuote quote ...;
return quote;
}
}
39
Standard Service
Channel
MethodInvokingRouter
<channel id="even"/>
<channel id="odd"/>
MethodInvokingRouter
<channel id="even"/>
<channel id="odd"/>
@Router
public String getParity(int i) {
return (i % 2 == 0) ? "even" : "odd";
}
43
PayloadtypeRouter
String Channel
Integer Channel
43
PayloadtypeRouter
String Channel
Integer Channel
router.handleMessage(new StringMessage("test"));
router.handleMessage(new GenericMessage(123));
44
ReceipientListRouter
Channel
Channel
44
ReceipientListRouter
Channel
Channel
channels.add(channel1);
channels.add(channel2);
router.handleMessage(message);
45
Channel Splitter
Channel
Aggregator
46
@Splitter
public List<OrderItem> splitOrder(PurchaseOrder order,
@Header("customerId") String customerId) {
// split the purchase order into order items…
}
46
@Splitter
public List<OrderItem> splitOrder(PurchaseOrder order,
@Header("customerId") String customerId) {
// split the purchase order into order items…
}
@Aggregator
public PurchaseOrder aggregateOrder(List<OrderItem> items) {
// aggregate the items into a single order object...
}
47
Channel
Adapter
48
Channel Adapters
Inbound
Message
Channel Adapters
Inbound
Message
Outbound
Message
File Adapter
<file:inbound-channel-adapter channel="filesIn"
directory="${java.io.tmpdir}/test-input">
<poller max-messages-per-poll="5">
<cron-trigger expression="*/10 * * * * MON-FRI"/>
</poller>
</file:inbound-channel-adapter>
<file:outbound-channel-adapter channel="filesOut"
directory="${java.io.tmpdir}/test-output"/>
50
JMS Adapter
<jms:inbound-channel-adapter channel="input"
connection-factory="connectionFactory"
destination-name="sourceQueueName"/>
<jms:outbound-channel-adapter channel="output"
destination="targetQueue"/>
<jms:inbound-gateway request-channel="inRequests"
destination="inboundRequestQueue"/>
<jms:outbound-gateway request-channel="outRequests"
reply-channel="replies" jms-queue="outQueue"/>
51
<channel id="channel"/>
<inbound-channel-adapter channel="channel"
ref="reader" method="read">
<poller max-messages-per-poll="1">
<interval-trigger interval="1000"/>
</poller>
</inbound-channel-adapter>
<outbound-channel-adapter channel="channel"
ref="writer" method="write"/>
52
Webservice Adapter
<ws:outbound-gateway uri="http://..."
marshaller="someMarshaller"
unmarshaller="someMarshaller"
request-channel="req" reply-channel="rep"/>
<ws:inbound-gateway request-channel="req"
reply-channel="rep"
marshaller="someMarshaller"
unmarshaller="someMarshaller" />
53
Other Adapters
> HTTP
> Mail
> RMI
> springsource.org/extensions
54
Q&A
Agim Emruli
agim.emruli@springsource.com
55
THANK
YOU!
56
Picture Credits
http://www.flickr.com/photos/scraplab/2612334635/
http://www.flickr.com/photos/mylifestory/527847004/
http://www.flickr.com/photos/alex-s/116511016/
http://www.flickr.com/photos/jdan/2324469981/
57
Picture Credits
http://www.flickr.com/photos/global-jet/2125557004/