Enterprise Integration with Spring Integration - Jazoonjazoon.com/history/Portals/0/Content/ArchivWebsite/jazoon.com/... · to solve common Enterprise Integration ... Systems. Enterprise

Post on 27-May-2018

245 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

Transcript

Enterprise Integration with Spring Integration

Agim EmruliSpringSource8100

2

Presentation Goal

Learn how Spring Integration helps to solve common Enterprise Integration challenges

3

IntegrationChallenges

4System Failures

5

IntolerantSystems

Enterprise Integration Patterns

6

Pattern Catalog Overview 7

Message Transformation

Content FIlter

Content

Enricher

Envelope

WrapperMessage

Translator

Normalizer

Claim Check

Message Construction

C

Command

Message

A B

Correlation ID

D

Document

Message

E

Event

Message

Message

Message

Sequence

Request

Reply

Return

Address

Message Routing

Aggregator

Content Based

Router

Composed

Message

Message

FIlter

Message

Router

Recipient List

Process

Manager

Splitter

8

How does Spring help ?

9

Spring Big Picture

Inversion of Control

Dependency Injection

Aspect oriented

Programming

Enterprise Service

Abstraction

10

Focus on Business domain

Spring Powered Applications11

Application

Maintain-able Flexible

RobustTestable

Layered Architecture 12

Layered Architecture 12

Domain Objects

Layered Architecture 12

Database Email Messaging

Domain Objects

Layered Architecture 12

Database Email Messaging

Infrastructure

Domain Objects

Layered Architecture 12

Database Email Messaging

Infrastructure

Domain ObjectsData Access

Layered Architecture 12

Database Email Messaging

Infrastructure

Domain Objects

Services

Data Access

AOP

Layered Architecture 12

Database Email Messaging

Infrastructure

Domain Objects

Services

Data Access

Layered Architecture13

Spring Application

Layered Architecture13

Spring Application

MVC

Layered Architecture13

Spring Application

RMIMVC

Layered Architecture13

Spring Application

Webservice RMIMVC

Layered Architecture13

Spring Application

Webservice RMIMVC

Batch

Layered Architecture13

Spring Application

Webservice RMIMVC

Batch JMS

Event Driven Architecture14

Event

Framework

Application

Spring JMS Support15

<jms:listener-container transaction-manager="txManager"> <jms:listener ref="orderService" method="order" destination="queue.orders" response-destination="queue.confirmation"/></jms:listener-container>

Spring JMS Support15

<jms:listener-container transaction-manager="txManager"> <jms:listener ref="orderService" method="order" destination="queue.orders" response-destination="queue.confirmation"/></jms:listener-container>

public class OrderService { public OrderConfirmation order(Order o) {..}

}

16

Introducing Spring Integration

17

Goals

18

Reuse ServiceLayer

19

Incremental Extension

Spring Integration Architecture20

Spring Integration Architecture20

Services

Spring Integration Architecture20

Services

Webservice

Spring Integration Architecture20

Services

Webservice File

Spring Integration Architecture20

Services

Webservice File

Spring Integration Architecture20

Services

Webservice File

Transformer

Spring Integration Architecture20

Services

Webservice

Router

File

Transformer

21

MessageConstruction

Message Structure22

Message HeaderSequence Number

Sequence SizeExpiration Date

Correlation Identifier

Message Body

C

Command

Message

D

Document

Message

E

Event

Message

Message Interface23

public interface Message<T> {

MessageHeaders getHeaders();

T getPayload();}

24Message Headers

24

MessageHeaders headers = message.getHeaders();

String value = headers.get("key", String.class);

Object id = headers.getId();

Long timestamp = headers.getTimestamp();

MessagePriority priority = headers.getPriority();

Message Headers

25Message 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();

Message Builder

26Channels And Endpoints

Message Channel27

Message Endpoint

Message Message

ChannelMessage Endpoint

Direct Channels28

Event-Driven

ConsumerMessage Endpoint Channel

Direct Channels28

Event-Driven

ConsumerMessage Endpoint Channel

<channel id="sync-p2p" />

Queue Channel29

Message Endpoint ChannelPolling

Consumer

Queue Channel29

Message Endpoint ChannelPolling

Consumer

<channel id="async-p2p"> <queue capacity="50" /></channel>

Publish-Subscribe Channel30

Message EndpointPublish Subscribe

Channel

Event-Driven

Consumer

Event-Driven

Consumer

Publish-Subscribe Channel30

Message EndpointPublish Subscribe

Channel

Event-Driven

Consumer

Event-Driven

Consumer

<publish-subscribe-channel id="pubsub" />

Priority Channel31

Message Endpoint ChannelPolling

Consumer

Resequencer

Priority Channel31

Message Endpoint ChannelPolling

Consumer

Resequencer

<channel id="priorityChannel"> <priority-queue comparator="someComp" /></channel>

32Message Transformation

Message Translator33

Channel ChannelMessage Translator

Message Translator33

<transformer input-channel="input" output-channel="output" ref="transformer" method="transform"/>

Channel ChannelMessage Translator

Annotation Based Message Translator34

@MessageEndpointpublic class MessageTransformer{ @Transformer(inputChannel="in",

outputChannel="out") public LoanRequest transform(Loan loan){ return ...; }}

35Service Activator

36

Service Activator

Channel

ChannelMessage Endpoint

Service Activator

Message Endpoint

Service Activator37

<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"/>

Annotation Based Service Activator38

@MessageEndpointpublic class LoanBroker {

@ServiceActivator(inputChannel="x", outputChannel="y") public LoanQuote processRequest(

LoanRequest request) { LoanQuote quote ...; return quote; }}

Polling and Transactions39

<service-activator ref="loanBroker" method="processRequest" input-channel="requests" output-channel="quotes"> <poller task-executor="pool1"> <interval-trigger interval="5000"/> <transactional propagation="REQUIRES_NEW"/> </poller></service-activator><pool-executor id="pool1" max-size="25"/><beans:bean id="transactionManager" ... />

40Message Routing

Content Based Router41

Standard Service

Channel

VIP Service Channel

Channel Content Based Router

MethodInvokingRouter42

<channel id="even"/>

<channel id="odd"/>

<router ref="parityResolver" input-channel="numbers"/>

MethodInvokingRouter42

<channel id="even"/>

<channel id="odd"/>

<router ref="parityResolver" input-channel="numbers"/>

@Routerpublic String getParity(int i) { return (i % 2 == 0) ? "even" : "odd";}

PayloadtypeRouter43

Channel

String Channel

Integer Channel

Content Based Router

PayloadtypeRouter43

typeMap .put(String.class, stringChannel);typeMap.put(Integer.class, integerChannel);

PayloadTypeRouter router = new PayloadTypeRouter();router.setPayloadTypeChannelMap(typeMap);

router.handleMessage(new StringMessage("test")); router.handleMessage(new GenericMessage(123));

Channel

String Channel

Integer Channel

Content Based Router

ReceipientListRouter44

Channel

Channel

Recipient ListChannel

ReceipientListRouter44

channels.add(channel1);channels.add(channel2);

RecipientListRouter router = new RecipientListRouter();router.setChannels(channels);Message<String> message = new StringMessage("test");

router.handleMessage(message);

Channel

Channel

Recipient ListChannel

Splitter And Aggregator45

Channel

ChannelAggregator

Splitter

Splitter And Aggregator46

@Splitterpublic List<OrderItem> splitOrder(PurchaseOrder order, @Header("customerId") String customerId) { // split the purchase order into order items…}

Splitter And Aggregator46

@Splitterpublic List<OrderItem> splitOrder(PurchaseOrder order, @Header("customerId") String customerId) { // split the purchase order into order items…}

@Aggregatorpublic PurchaseOrder aggregateOrder(List<OrderItem> items) { // aggregate the items into a single order object...}

47

ChannelAdapter

Channel Adapters48

External System ChannelChannel Adapter

Message

Inbound

Channel Adapters48

External System ChannelChannel Adapter

Message

Inbound

External SystemChannel Channel Adapter

Message

Outbound

File Adapter49

<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"/>

JMS Adapter50

<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"/>

Method Invoking Adapter51

<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"/>

Webservice Adapter52

<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" />

Other Adapters53

> HTTP> Mail> RMI > springsource.org/extensions

54

Q & AAgim Emruliagim.emruli@springsource.com

55

THANK YOU!

Picture Credits57

http://www.flickr.com/photos/global-jet/2125557004/

top related