Spring integration

12

Click here to load reader

Transcript of Spring integration

Page 1: Spring integration

Spring frameworkMotto: Musíte rozbít vejce když chcete udělat omeletu

Spring framework training materials by Roman Pichlík is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.

Sunday 13 May 2012

Page 2: Spring integration

Spring Integration Integruju, integruješ, integurjeme

Sunday 13 May 2012

Page 3: Spring integration

Integration scenarios

• File transfer

• Shared database

• Remote Procedure Call

• Messaging

Sunday 13 May 2012

Page 4: Spring integration

Goals And Principles

• Provide a simple model for implementing complex enterprise integration solutions

• Facilitate asynchronous, message-driven behavior within a Spring-based application

• Promote intuitive, incremental adoption for existing Spring users

Sunday 13 May 2012

Page 5: Spring integration

Channel

• Point-to-Point

• Publish-Subscribe

Sunday 13 May 2012

PublishSubscribeChannelQueueChannelPriorityChannelRendezvousChannel

Page 6: Spring integration

Endpoints

Sunday 13 May 2012

Page 7: Spring integration

• Message Channels

• Message Endpoints

• Service Activator

• Channel Adapter

• Router

• Filter

• Transformer

• Splitter

• Aggregator

• ResequencerSunday 13 May 2012

Page 8: Spring integration

Router

Sunday 13 May 2012A Message Router is responsible for deciding what channel or channels should receive the Message next (if any). Typically the decision is based upon the Message's content and/or metadata available in the Message Headers. A Message Router is often used as a dynamic alternative to a statically configured output channel on a Service Activator or other endpoint capable of sending reply Messages. Likewise, a Message Router provides a proactive alternative to the reactive Message Filters used by multiple subscribers as described above.

Page 9: Spring integration

Service activator

Sunday 13 May 2012The Service Activator invokes an operation on some service object to process the request Message, extracting the request Message's payload and converting if necessary (if the method does not expect a Message-typed parameter). Whenever the service object's method returns a value, that return value will likewise be converted to a reply Message if necessary (if it's not already a Message). That reply Message is sent to the output channel. If no output channel has been configured, then the reply will be sent to the channel specified in the Message's "return address" if available.

Page 10: Spring integration

Channel adapter

An inbound "Channel Adapter" endpoint connects a source system to a MessageChannel

An outbound "Channel Adapter" endpoint connects a MessageChannel to a target system.

Sunday 13 May 2012A Channel Adapter is an endpoint that connects a Message Channel to some other system or transport. Channel Adapters may be either inbound or outbound. Typically, the Channel Adapter will do some mapping between the Message and whatever object or resource is received-from or sent-to the other system (File, HTTP Request, JMS Message, etc). Depending on the transport, the Channel Adapter may also populate or extract Message header values. Spring Integration provides a number of Channel Adapters, and they will be described in upcoming chapters.

Page 11: Spring integration

Příklad

Sunday 13 May 2012

Page 12: Spring integration

<si:channel id="input" />

<si:channel id="output"> <si:queue capacity="10" /> </si:channel>

<si:service-activator input-channel="input" output-channel="output" ref="convertor" method="toUpper" /> <bean id="convertor" class="cz.sweb.pichlik.Convertor"></bean>

public class Convertor { public String toUpper(String s) { return s.toUpperCase(); }}

ApplicationContext context = new ClassPathXmlApplicationContext("classpath:META-INF/applicationContext.xml"); MessageChannel input = (MessageChannel) context.getBean("input"); PollableChannel output = (PollableChannel) context.getBean("output"); input.send(new StringMessage("Spring Integration rocks")); Message reply = output.receive(); System.out.println("received: " + reply);

Sunday 13 May 2012