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

Post on 06-Feb-2018

226 Views

Category:

Documents

1 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Spring Integration Framework with Maven and JBoss

“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

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

Spring Integration Architecture

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

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

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

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

Message Translator

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

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)’ }

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

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

}

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

Types of channels

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

Channel

• Priority Channel

Message Transformation

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

Service Activator

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

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

Content based Router

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

Payloadtype Router

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

RecipientList Router

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

Splitter And Aggregator

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

Channel Adapter

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

Types:

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

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

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

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

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

Why go for Spring Integration

?? ?? ??

• 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

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.

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

top related