spring integration framework with maven and jboss · pdf filemaven and jboss “enterprise...

36

Upload: docong

Post on 06-Feb-2018

220 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Spring Integration Framework with Maven and JBoss · PDF fileMaven and JBoss “Enterprise Application Integration (EAI) is defined as the
Page 2: Spring Integration Framework with Maven and JBoss · PDF fileMaven and JBoss “Enterprise Application Integration (EAI) is defined as the

Spring Integration Framework with Maven and JBoss

Page 3: Spring Integration Framework with Maven and JBoss · PDF fileMaven and JBoss “Enterprise Application Integration (EAI) is defined as the

“Enterprise Application Integration (EAI) is defined as the uses of software and computer systems architectural principles to integrate a set of enterprise computer applications” Wikipedia Messaging is the most common approach to EAI and the basis for Spring Integration

Enterprise Application Integration

Page 4: Spring Integration Framework with Maven and JBoss · PDF fileMaven and JBoss “Enterprise Application Integration (EAI) is defined as the

What is Messaging? •  Example: Restaurant Scenarioà you want to have a dish and

so ask the waiter for the same. The waiter in turn informs the cook to prepare it. This is messaging

•  Characteristics: 1.  Transport---The waiter takes an order and moves it to the

cook 2.  Asynchronous--Different actors do different things in

parallel 3.  Translation---menu item => number => recipe 4.  Routing---Orders arrive back at the proper table

Page 5: Spring Integration Framework with Maven and JBoss · PDF fileMaven and JBoss “Enterprise Application Integration (EAI) is defined as the

Spring Integration Architecture

Page 6: Spring Integration Framework with Maven and JBoss · PDF fileMaven and JBoss “Enterprise Application Integration (EAI) is defined as the

In Spring Integration the format of the message is

•  Header contains: 1. Sequence Number 2. Sequence Size 3. Expiration Date 4. Correlation Identifier 5. Return Address 6. Transport Info

Page 7: Spring Integration Framework with Maven and JBoss · PDF fileMaven and JBoss “Enterprise Application Integration (EAI) is defined as the

Message Channel 1.  Decouples producers from consumers 2.  Supports Point to Point publish/subscribe 3.  Enforces data type consistency

Page 8: Spring Integration Framework with Maven and JBoss · PDF fileMaven and JBoss “Enterprise Application Integration (EAI) is defined as the

Channel Adapter

•  Connect a source to the messaging system so it can send to a Message Channel

•  Connect a source to the messaging system so it can send to a Message Channel

Page 9: Spring Integration Framework with Maven and JBoss · PDF fileMaven and JBoss “Enterprise Application Integration (EAI) is defined as the

Service Activator • A Message Endpoint that invokes a service •  Supports multiple communication styles – one-way and request-reply – synchronous and asynchronous •  The service is unaware of the messaging system

Page 10: Spring Integration Framework with Maven and JBoss · PDF fileMaven and JBoss “Enterprise Application Integration (EAI) is defined as the

Message Translator

• Payload Transformer – converts the type or format of a Message •  Header Transformer – add-to or remove-from the Message Headers

Page 11: Spring Integration Framework with Maven and JBoss · PDF fileMaven and JBoss “Enterprise Application Integration (EAI) is defined as the

Components needed for spring integration

Ø  Message Target § Interface for any component to which Messages can be sent Ex: public interface MessageTarget{ boolean send(Message message)’ }

Page 12: Spring Integration Framework with Maven and JBoss · PDF fileMaven and JBoss “Enterprise Application Integration (EAI) is defined as the

Ø PollableSource § Interface for components from which § Polling Consumers can receive Messages

public interface PollableSource<T> extends MessageSource{ Message<T> receive();

}

Page 13: Spring Integration Framework with Maven and JBoss · PDF fileMaven and JBoss “Enterprise Application Integration (EAI) is defined as the

Message Builder Message<String> message = MessageBuilder.withPayload("test") .setHeader(“JBossText", 123) .setPriority(MessagePriority.HIGHEST) .build(); Message<String> copy = MessageBuilder.fromMessage(message) .setHeader("BossText", 456) .setHeaderIfAbsent("bar", 789) .build();

Page 14: Spring Integration Framework with Maven and JBoss · PDF fileMaven and JBoss “Enterprise Application Integration (EAI) is defined as the

Types of channels

1.  Direct Channel 2.  Message Channel 3.  Queue Channel 4.  Publish Subscribe

Channel

Page 15: Spring Integration Framework with Maven and JBoss · PDF fileMaven and JBoss “Enterprise Application Integration (EAI) is defined as the

• Priority Channel

Page 16: Spring Integration Framework with Maven and JBoss · PDF fileMaven and JBoss “Enterprise Application Integration (EAI) is defined as the

Message Transformation

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

Page 17: Spring Integration Framework with Maven and JBoss · PDF fileMaven and JBoss “Enterprise Application Integration (EAI) is defined as the

Service Activator

Page 18: Spring Integration Framework with Maven and JBoss · PDF fileMaven and JBoss “Enterprise Application Integration (EAI) is defined as the

Continue….

<channel id="requests"/> <channel id="quotes"/> <service-activator input-channel="requests" ref=“serviceActivator" method="processRequest" output-channel="quotes"/> <beans:bean id=" serviceActivator "class=“jboss.serviceActivator"/>

Page 19: Spring Integration Framework with Maven and JBoss · PDF fileMaven and JBoss “Enterprise Application Integration (EAI) is defined as the

Route the message

• We have different types of routers which are used to route the message from source to different destinations. They are:

1.  Content based Router 2.  Payloadtype Router 3.  RecipientList Router 4.  Splitter And Aggregator

Page 20: Spring Integration Framework with Maven and JBoss · PDF fileMaven and JBoss “Enterprise Application Integration (EAI) is defined as the

Content based Router

<channel id="even"/> <channel id="odd"/> <router ref="parityResolver" inputchannel="numbers"/>

Page 21: Spring Integration Framework with Maven and JBoss · PDF fileMaven and JBoss “Enterprise Application Integration (EAI) is defined as the

Payloadtype Router

Page 22: Spring Integration Framework with Maven and JBoss · PDF fileMaven and JBoss “Enterprise Application Integration (EAI) is defined as the

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));

Page 23: Spring Integration Framework with Maven and JBoss · PDF fileMaven and JBoss “Enterprise Application Integration (EAI) is defined as the

RecipientList Router

Page 24: Spring Integration Framework with Maven and JBoss · PDF fileMaven and JBoss “Enterprise Application Integration (EAI) is defined as the

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

Page 25: Spring Integration Framework with Maven and JBoss · PDF fileMaven and JBoss “Enterprise Application Integration (EAI) is defined as the

Splitter And Aggregator

Page 26: Spring Integration Framework with Maven and JBoss · PDF fileMaven and JBoss “Enterprise Application Integration (EAI) is defined as the

@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... }

Page 27: Spring Integration Framework with Maven and JBoss · PDF fileMaven and JBoss “Enterprise Application Integration (EAI) is defined as the

Channel Adapter

A Channel Adapter is a Message Endpoint that enables connecting a single sender or receiver to a Message Channel

Page 28: Spring Integration Framework with Maven and JBoss · PDF fileMaven and JBoss “Enterprise Application Integration (EAI) is defined as the

Types:

1.  File Adapter 2.  JMS Adapter 3.  Method Invoking Adapter 4.  WebService Adapter 5.  Http 6.  Mail 7.  RMI

Page 29: Spring Integration Framework with Maven and JBoss · PDF fileMaven and JBoss “Enterprise Application Integration (EAI) is defined as the

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

Page 30: Spring Integration Framework with Maven and JBoss · PDF fileMaven and JBoss “Enterprise Application Integration (EAI) is defined as the

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

Page 31: Spring Integration Framework with Maven and JBoss · PDF fileMaven and JBoss “Enterprise Application Integration (EAI) is defined as the

Method Invoking Adapter

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

Page 32: Spring Integration Framework with Maven and JBoss · PDF fileMaven and JBoss “Enterprise Application Integration (EAI) is defined as the

Webservice Adapter

<ws:outbound-gateway uri="http://example.com" marshaller="someMarshaller" unmarshaller="someMarshaller" request-channel="req" reply-channel="rep"/> <ws:inbound-gateway request-channel="req" reply-channel="rep" marshaller="someMarshaller" unmarshaller="someMarshaller" />

Page 33: Spring Integration Framework with Maven and JBoss · PDF fileMaven and JBoss “Enterprise Application Integration (EAI) is defined as the

Why go for Spring Integration

?? ?? ??

Page 34: Spring Integration Framework with Maven and JBoss · PDF fileMaven and JBoss “Enterprise Application Integration (EAI) is defined as the

• Can be used from within an existing application. • Lightweight (like any Spring application): – run from JUnit test – run within webapp • Focussed on integration, not on ESB

Page 35: Spring Integration Framework with Maven and JBoss · PDF fileMaven and JBoss “Enterprise Application Integration (EAI) is defined as the

Others in general

• Full blown ESB • It’s an application, not a framework – You need to install it – You need to run it • Typically a lot heavier • Focus on the deployment architecture (SOA) not the actual integration.

Page 36: Spring Integration Framework with Maven and JBoss · PDF fileMaven and JBoss “Enterprise Application Integration (EAI) is defined as the

Credits 1. Spring Integration Home Page: – http://www.springframework.org/spring-integration 2. http://jazoon.com/portals/0/Content/ArchivWebsite/jazoon.com/jazoon09/download/presentations/8100.pdf 3. http://www.itcork.ie/contentfiles/eventresources/Jonas%20Partner%20-%20Spring%20Integration.pdf