SlideShare a Scribd company logo
Spring Integration
Zülfikar Karakaya
• EIP + dependency injection + method invocation
• event driven architecture
• low coupling and high cohesion
• pipes-and-filters architectural design
intra-
application
inter
application
Two areas of focus for Spring Integration
• lightweight intra-application messaging
• flexible interapplication integration
The Spring Integration 2.0 distribution
includes support for the following adapters
Filesystem, FTP, or Secured File Transfer Protocol (SFTP)
User Datagram Protocol (UDP)
Transmission Control Protocol (TCP)
HTTP (Representational State Transfer [REST])
Web services (SOAP)
Mail (POP3 or IMAP for receiving, SMTP for sending)
Java Message Service (JMS)
Java Database Connectivity (JDBC)
Java Management Extensions (JMX)
Remote Method Invocation (RMI)
Really Simple Syndication (RSS) feeds
Twitter
Extensible Messaging and Presence Protocol (XMPP)
channel adapters (unidirectional) or
gateways (bidirectional)
three base enterprise integration patterns
message, message channel, and message endpoint
The message’s payload may be XML, a simple string, or a primary
key referencing a record in a database
Messages can have different functions. For example, a Command Message tells the
receiver to do something, an Event Message notifies the receiver
that something has happened, and a Document Message transfers some data from
the sender to the receiver.
The Message!
Message Channels
• connection between multiple endpoints
• how and where a message is delivered
• key enabler for loose coupling
• can be categorized as
– according to the handoff type, synchronous or asynchronous
– according to the delivery type,
• point-to-point (should include support for load balancing and
failover)
• publish-subscribe (require failure-handling patterns)
• channel adapters
• messaging gateways
• service activators
Message Endpoints
• Message endpoints are the components that actually do something with the
message.
• Message endpoints basically provide the connections between functional services
and the messaging framework.
• A message can leave the channel successfully only by being consumed by an
endpoint, and a message can enter the channel only by being produced by an
endpoint.
CHANNEL ADAPTER
• Connects an application to the messaging system.
• Channel adapter is placed at the beginning and the end of a
unidirectional message flow.
• Many different kinds of channel adapters exist, ranging from a
method-invoking channel adapter to a web service channel adapter.
MESSAGING GATEWAY
Outbound gateways can be used for invoking web services and for
synchronous
request-reply interactions over JMS
SERVICE ACTIVATOR
• is a component that invokes a service based on an incoming
message and sends an outbound message based on the return
value of this service invocation.
• in Spring Integration, the definition is constrained to local method
calls.
• a service activator as a method-invoking outbound gateway.
ROUTER
• determines the next channel a message should be sent to based on
the incoming message.
• can be useful to send messages with different payloads to different,
specialized consumers (Content-Based Router).
SPLITTER
• A Splitter is useful whenever the act of processing message content
can be split into multiple steps and executed by different
consumers at the same time.
• An Aggregator waits for a group of correlated messages and
merges them together when the group is complete.
• A splitter and an aggregator are often used in a symmetric setup,
where some work is done in parallel after a splitter, and the
aggregated result is sent back to the upstream gateway.
AGGREGATOR
<splitter input-channel="orders"
output-channel="items"/>
<aggregator input-channel="processedItems"
release-strategy="orderCompletionChecker"
output-channel="processedOrders"/>
• Strategy Method pattern
• Visit www.springframework.org/schema/integration to explore Spring
Integration’s various XML schema namespace configurations.
a simple JMS example
public interface MessageListener {
void onMessage(Message message);
}
<jms:listener-container>
<jms:listener destination="someDestination"
ref="someListenerImplementsJMSMessageListener" />
</jms:listener-container>
public class HelloService {
public String sayHello(String name) {...}
}
<jms:listener-container>
<jms:listener destination="helloRequests" ref="helloService"
method="sayHello" />
</jms:listener-container>
<bean id="helloService" class="example.HelloService" />
JMS default message
listener interface,
no return value
a custom method with
return value,
no scheduling
schedule a file poller
Runnable task = new Runnable() {
public void run() {
File file = filePoller.poll();
if (file != null) {
fileProcessor.process(file);
}
}
};
long initialDelay = 0;
long rate = 60;
ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(5);
scheduler.scheduleAtFixedRate(task, initialDelay, rate,TimeUnit.SECONDS);
<task:scheduled-tasks scheduler="myScheduler">
<task:scheduled ref="filePoller" method="poll"fixed-rate="60000" />
</task:scheduled-tasks>
<task:scheduler id="myScheduler" pool-size="5" />
Scheduling a task
programmatically
Scheduling a task with Spring
Spring Integration way
message listener + method invoker + task scheduler
<file:inbound-channel-adapter directory="/tmp/example"
channel="files">
<poller max-messages-per-poll="10"
cron="0 * 9-17 * * MON-FRI"/>
</file:inbound-channel-adapter>
<service-activator input-channel="files" ref="helloService"
method="sayHello"/>
JMS cons
dependency on the JMS API
this inhibits testing and also pollutes the business logic
Light-weight with Spring only, without spring an EJB container required
with version 2.0, Spring introduced its own MessageListener containers as a lightweight
alternative
As with message-driven beans, a listener is registered with a certain JMS destination
but with Spring, the listener’s container is a simple object that is itself managed by
Spring.
JMS default message listener has a void return type
That means you can’t easily send a reply message from the listener method’s
implementation
RPC cons
certain detail about remoting can’t be safely hidden or ignored
serialization
Hello World example
Gateway
Note that the gateway element refers to a service interface. This is similar to
the way the Spring Framework handles remoting.
The caller should only need to be aware of an interface, while the framework
creates a proxy that implements that interface.
The proxy is responsible for handling the underlying concerns such as
serialization and remote invocation, or in this case, message construction and
delivery
Wire Tap
allows you to route messages to a separate location while they are being
forwarded to the ultimate destination.
avoid coupling
<beans:bean id="bookingDao" class="example.SimpleBookingDao" />
<beans:bean id="bookingService" class="example.BookingService">
<beans:constructor-arg ref="bookingDao" />
</beans:bean>
<channel id="mealPreferenceUpdatesChannel" />
<service-activator input-channel="mealPreferenceUpdatesChannel"
output-channel="bookingEnrichedMealUpdates" ref="bookingService"
method="populatePreference" />
<channel id="bookingEnrichedMealUpdates" />
<beans:bean id="updateRequestTransformer"
class="example.MealPreferenceRequestTransformer" />
<service-activator input-channel="bookingEnrichedMealUpdates"
output-channel="xmlMealUpdates" ref="updateRequestTransformer"
method="buildMealPreferenceUpdateRequest" />
<channel id="xmlMealUpdates" />
<ws:outbound-gateway uri="http://example.com/mealupdates"
request-channel="xmlMealUpdates" />
method invocations with message
passing over channels
Reducing coupling is one of the
main concerns when integrating
applications
Event-driven architecture (EDA) is an architectural pattern in which complex applications
are broken down into a set of components or services that interact via events
Where events are communicated via channels that can act as buffers in
periods of high throughput, such a system can be described as having a staged event driven
architecture (SEDA). SEDA-based systems generally respond better to significant
spikes in load than do standard multithreaded applications and are also easier to
configure at runtime, for example, by modifying the number of consumers processing
a certain event type. This allows for optimizations based on the actual requirements of
the application, which in turn provides a better usage experience
Spring Integration provides the building blocks to create both EDA and SEDA applications.
Event-Driven Consumer pattern, but here the consumer is consuming messages rather
than events - it’s just that the consumption is triggered by the event of a message
becoming available.
Event driven architecture
Synchronous and asynchronous communication compared
Traditionally, the integration between enterprise
applications is based on message-driven, asynchronous mechanisms
<channel id="input" />
<payload-type-router input-channel="input">
<mapping type="example.Order" channel="orders"/>
<mapping type="example.Notification" channel="notifications"/>
</payload-type-router>
<channel id="orders" />
<channel id="notifications" />
<service-activator ref="ordersProcessor"
input-channel="orders" output-channel="results" />
<service-activator ref="notificationsProcessor"
input-channel="notifications" output-channel="results" />
<channel id="results" />
Spring Integration Way
Spring Integration Way
The structure doesn’t seem to tell what
kind of interaction takes place
(is it synchronous
or asynchronous?)
Spring Integration supports both approaches by using two different
types of message channels
DirectChannel (synchronous) and QueueChannel (asynchronous)
Both types of channels are configured using the same <channel/>
element. By default, its behavior is synchronous
If you want to buffer the messages instead of passing them
directly through a channel and to follow an asynchronous approach, you
can use a queue to store them, like this
<channel id="input">
<queue capacity="10"/>
</channel>
Spring Integration Way
Message (Revisited)
public interface Message<T> {
MessageHeaders getHeaders();
T getPayload();
}
public final class MessageHeaders
implements Map<String, Object>, Serializable {
/* implementation omitted */
}
message headers are immutable
to avoid issues with concurrency
Channels
public interface MessageChannel {
boolean send(Message<?> message);
boolean send(Message<?> message, long timeout);
}
it provides
no methods for receiving messages
Channels
public interface SubscribableChannel extends MessageChannel {
boolean subscribe(MessageHandler handler);
boolean unsubscribe(MessageHandler handler);
}
I’ll let you know when I’ve got something!
Do you have any messages for me?
public interface PollableChannel extends MessageChannel {
Message<?> receive();
Message<?> receive(long timeout);
}
Selecting right channel for the job
In Spring Integration, the default channels are
SubscribableChannels, and the message
transmission is synchronous.
So there is one thread and single transaction here
<channel id="bookingConfirmationRequests"/>
<service-activator input-channel="bookingConfirmationRequests"
output-channel="chargedBookings"
ref="billForBookingService" />
<channel id="chargedBookings" />
<service-activator input-channel="chargedBookings"
output-channel="emailConfirmationRequests"
ref="seatAvailabilityService" />
<channel id="emailConfirmationRequests" />
<outbound-channel-adapter channel="emailConfirmationRequests"
ref="emailConfirmationService" />
Email is slow and our servers are unreliable
<channel id="emailConfirmationRequests">
<queue />
</channel>
what if you need to connect one producer
with not just one, but two (or more) consumers?
Telling everyone who needs to know that a booking occured
<service-activator input-channel="chargedBookings"
output-channel="emailConfirmationRequests"
ref="seatAvailabilityService" />
<publish-subscribe-channel id="completedBookings" />
<bridge input-channel="completedBookings"
output-channel="emailConfirmationRequests" />
<channel id="emailConfirmationRequests">
<queue />
</channel>
Some customers are more equal than others
<channel id="bookingConfirmationRequests">
<priority-queue comparator="customerPriorityComparator" />
</channel>
this causes the framework to instantiate an instance of PriorityChannel
you can provide an instance of a class implementing
Comparator<Message<?>>
Endpoints
• Polling or event-driven
• Inbound or outbound
• Unidirectional or bidirectional
• Internal or external
References
Spring Integration in Action,
MARK FISHER, JONAS PARTNER, MARIUS BOGOEVICI, IWEIN FULD
Spring Integration
Zülfikar Karakaya

More Related Content

PDF
Messaging Standards and Systems - AMQP & RabbitMQ
PPTX
Testing microservices with rest assured
PPTX
IBM Integration Bus and REST APIs - Sanjay Nagchowdhury
PDF
RxJS Evolved
PPTX
Express JS
PPTX
Intro To Mongo Db
PDF
OAuth2 and Spring Security
PDF
PromQL Deep Dive - The Prometheus Query Language
Messaging Standards and Systems - AMQP & RabbitMQ
Testing microservices with rest assured
IBM Integration Bus and REST APIs - Sanjay Nagchowdhury
RxJS Evolved
Express JS
Intro To Mongo Db
OAuth2 and Spring Security
PromQL Deep Dive - The Prometheus Query Language

What's hot (20)

PDF
[2019] 200만 동접 게임을 위한 MySQL 샤딩
PPTX
Multi tenant architecture
PDF
ClickHouse Query Performance Tips and Tricks, by Robert Hodges, Altinity CEO
PPTX
AWS Route53 Fundamentals
PPT
Spring data presentation
PPTX
Using XSLT in Mule
PDF
Apigee Edge: Intro to Microgateway
PPTX
Publish & Subscribe to events using an Event Aggregator
PDF
A Fast Intro to Fast Query with ClickHouse, by Robert Hodges
PDF
The evolution of asynchronous javascript
PPTX
An introduction to OAuth 2
PDF
Reactive Web 101: WebFlux, WebClient, and Reactor Netty
PPTX
Microsoft LAPS - Local Administrator Password Solution
PPTX
btNOG 6: Next Generation Internet Registry Services - RDAP
PPTX
Spring Boot and REST API
PPTX
Micro services Architecture
PPT
Maven Introduction
PPTX
Test your microservices with REST-Assured
PDF
Dual write strategies for microservices
[2019] 200만 동접 게임을 위한 MySQL 샤딩
Multi tenant architecture
ClickHouse Query Performance Tips and Tricks, by Robert Hodges, Altinity CEO
AWS Route53 Fundamentals
Spring data presentation
Using XSLT in Mule
Apigee Edge: Intro to Microgateway
Publish & Subscribe to events using an Event Aggregator
A Fast Intro to Fast Query with ClickHouse, by Robert Hodges
The evolution of asynchronous javascript
An introduction to OAuth 2
Reactive Web 101: WebFlux, WebClient, and Reactor Netty
Microsoft LAPS - Local Administrator Password Solution
btNOG 6: Next Generation Internet Registry Services - RDAP
Spring Boot and REST API
Micro services Architecture
Maven Introduction
Test your microservices with REST-Assured
Dual write strategies for microservices
Ad

Viewers also liked (7)

PPTX
Spring integration
PDF
EIP In Practice
PPT
Spring Integration
KEY
S2GX 2012 - Introduction to Spring Integration and Spring Batch
PDF
Spring Integration and EIP Introduction
PDF
The Technical SEO Renaissance
PPTX
Workshop Spring - Session 5 - Spring Integration
Spring integration
EIP In Practice
Spring Integration
S2GX 2012 - Introduction to Spring Integration and Spring Batch
Spring Integration and EIP Introduction
The Technical SEO Renaissance
Workshop Spring - Session 5 - Spring Integration
Ad

Similar to Spring integration (20)

PDF
quickguide-einnovator-11-spring-integration
PPTX
JDC2008 - Enterprise Integration and Service Oriented Design
PDF
Enterprise Integration Patterns with Spring integration!
PPTX
Sprintintegration ajip
PPTX
Srping integration
PPTX
Integration Patterns With Spring integration
PDF
(Oleg zhurakousky)spring integration-scala-intro
PDF
Russell 2012 introduction to spring integration and spring batch
ODP
Mihalache catalin eip with spring integration
PPT
Spring integration
PPTX
«Spring Integration as Integration Patterns Provider»
PDF
Spring integration
PPTX
Spring Integration
PPTX
Introduction to Kafka with Spring Integration
KEY
Spring integration motivation and history
PPTX
Enterprise Integration Patterns - Spring way
PPTX
Messaging with Spring Integration
PDF
Spring integration
PDF
Developing real-time data pipelines with Spring and Kafka
PDF
Spring Integration: from XML to Java DSL
quickguide-einnovator-11-spring-integration
JDC2008 - Enterprise Integration and Service Oriented Design
Enterprise Integration Patterns with Spring integration!
Sprintintegration ajip
Srping integration
Integration Patterns With Spring integration
(Oleg zhurakousky)spring integration-scala-intro
Russell 2012 introduction to spring integration and spring batch
Mihalache catalin eip with spring integration
Spring integration
«Spring Integration as Integration Patterns Provider»
Spring integration
Spring Integration
Introduction to Kafka with Spring Integration
Spring integration motivation and history
Enterprise Integration Patterns - Spring way
Messaging with Spring Integration
Spring integration
Developing real-time data pipelines with Spring and Kafka
Spring Integration: from XML to Java DSL

Recently uploaded (20)

PDF
System and Network Administraation Chapter 3
PDF
top salesforce developer skills in 2025.pdf
PPTX
L1 - Introduction to python Backend.pptx
PPTX
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
PDF
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
PDF
Which alternative to Crystal Reports is best for small or large businesses.pdf
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PDF
Softaken Excel to vCard Converter Software.pdf
PDF
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
PPTX
Introduction to Artificial Intelligence
PDF
How to Migrate SBCGlobal Email to Yahoo Easily
PDF
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
PPT
Introduction Database Management System for Course Database
PDF
Design an Analysis of Algorithms II-SECS-1021-03
PDF
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PDF
Odoo Companies in India – Driving Business Transformation.pdf
PPTX
CHAPTER 12 - CYBER SECURITY AND FUTURE SKILLS (1) (1).pptx
PPTX
ai tools demonstartion for schools and inter college
PPTX
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
System and Network Administraation Chapter 3
top salesforce developer skills in 2025.pdf
L1 - Introduction to python Backend.pptx
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
Which alternative to Crystal Reports is best for small or large businesses.pdf
Upgrade and Innovation Strategies for SAP ERP Customers
Softaken Excel to vCard Converter Software.pdf
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
Introduction to Artificial Intelligence
How to Migrate SBCGlobal Email to Yahoo Easily
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
Introduction Database Management System for Course Database
Design an Analysis of Algorithms II-SECS-1021-03
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
Odoo Companies in India – Driving Business Transformation.pdf
CHAPTER 12 - CYBER SECURITY AND FUTURE SKILLS (1) (1).pptx
ai tools demonstartion for schools and inter college
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises

Spring integration

  • 2. • EIP + dependency injection + method invocation • event driven architecture • low coupling and high cohesion • pipes-and-filters architectural design
  • 3. intra- application inter application Two areas of focus for Spring Integration • lightweight intra-application messaging • flexible interapplication integration
  • 4. The Spring Integration 2.0 distribution includes support for the following adapters Filesystem, FTP, or Secured File Transfer Protocol (SFTP) User Datagram Protocol (UDP) Transmission Control Protocol (TCP) HTTP (Representational State Transfer [REST]) Web services (SOAP) Mail (POP3 or IMAP for receiving, SMTP for sending) Java Message Service (JMS) Java Database Connectivity (JDBC) Java Management Extensions (JMX) Remote Method Invocation (RMI) Really Simple Syndication (RSS) feeds Twitter Extensible Messaging and Presence Protocol (XMPP) channel adapters (unidirectional) or gateways (bidirectional)
  • 5. three base enterprise integration patterns message, message channel, and message endpoint
  • 6. The message’s payload may be XML, a simple string, or a primary key referencing a record in a database Messages can have different functions. For example, a Command Message tells the receiver to do something, an Event Message notifies the receiver that something has happened, and a Document Message transfers some data from the sender to the receiver. The Message!
  • 7. Message Channels • connection between multiple endpoints • how and where a message is delivered • key enabler for loose coupling • can be categorized as – according to the handoff type, synchronous or asynchronous – according to the delivery type, • point-to-point (should include support for load balancing and failover) • publish-subscribe (require failure-handling patterns)
  • 8. • channel adapters • messaging gateways • service activators Message Endpoints • Message endpoints are the components that actually do something with the message. • Message endpoints basically provide the connections between functional services and the messaging framework. • A message can leave the channel successfully only by being consumed by an endpoint, and a message can enter the channel only by being produced by an endpoint.
  • 9. CHANNEL ADAPTER • Connects an application to the messaging system. • Channel adapter is placed at the beginning and the end of a unidirectional message flow. • Many different kinds of channel adapters exist, ranging from a method-invoking channel adapter to a web service channel adapter.
  • 10. MESSAGING GATEWAY Outbound gateways can be used for invoking web services and for synchronous request-reply interactions over JMS
  • 11. SERVICE ACTIVATOR • is a component that invokes a service based on an incoming message and sends an outbound message based on the return value of this service invocation. • in Spring Integration, the definition is constrained to local method calls. • a service activator as a method-invoking outbound gateway.
  • 12. ROUTER • determines the next channel a message should be sent to based on the incoming message. • can be useful to send messages with different payloads to different, specialized consumers (Content-Based Router).
  • 13. SPLITTER • A Splitter is useful whenever the act of processing message content can be split into multiple steps and executed by different consumers at the same time. • An Aggregator waits for a group of correlated messages and merges them together when the group is complete. • A splitter and an aggregator are often used in a symmetric setup, where some work is done in parallel after a splitter, and the aggregated result is sent back to the upstream gateway. AGGREGATOR
  • 14. <splitter input-channel="orders" output-channel="items"/> <aggregator input-channel="processedItems" release-strategy="orderCompletionChecker" output-channel="processedOrders"/> • Strategy Method pattern • Visit www.springframework.org/schema/integration to explore Spring Integration’s various XML schema namespace configurations.
  • 15. a simple JMS example public interface MessageListener { void onMessage(Message message); } <jms:listener-container> <jms:listener destination="someDestination" ref="someListenerImplementsJMSMessageListener" /> </jms:listener-container> public class HelloService { public String sayHello(String name) {...} } <jms:listener-container> <jms:listener destination="helloRequests" ref="helloService" method="sayHello" /> </jms:listener-container> <bean id="helloService" class="example.HelloService" /> JMS default message listener interface, no return value a custom method with return value, no scheduling
  • 16. schedule a file poller Runnable task = new Runnable() { public void run() { File file = filePoller.poll(); if (file != null) { fileProcessor.process(file); } } }; long initialDelay = 0; long rate = 60; ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(5); scheduler.scheduleAtFixedRate(task, initialDelay, rate,TimeUnit.SECONDS); <task:scheduled-tasks scheduler="myScheduler"> <task:scheduled ref="filePoller" method="poll"fixed-rate="60000" /> </task:scheduled-tasks> <task:scheduler id="myScheduler" pool-size="5" /> Scheduling a task programmatically Scheduling a task with Spring
  • 17. Spring Integration way message listener + method invoker + task scheduler <file:inbound-channel-adapter directory="/tmp/example" channel="files"> <poller max-messages-per-poll="10" cron="0 * 9-17 * * MON-FRI"/> </file:inbound-channel-adapter> <service-activator input-channel="files" ref="helloService" method="sayHello"/>
  • 18. JMS cons dependency on the JMS API this inhibits testing and also pollutes the business logic Light-weight with Spring only, without spring an EJB container required with version 2.0, Spring introduced its own MessageListener containers as a lightweight alternative As with message-driven beans, a listener is registered with a certain JMS destination but with Spring, the listener’s container is a simple object that is itself managed by Spring. JMS default message listener has a void return type That means you can’t easily send a reply message from the listener method’s implementation RPC cons certain detail about remoting can’t be safely hidden or ignored serialization
  • 19. Hello World example Gateway Note that the gateway element refers to a service interface. This is similar to the way the Spring Framework handles remoting. The caller should only need to be aware of an interface, while the framework creates a proxy that implements that interface. The proxy is responsible for handling the underlying concerns such as serialization and remote invocation, or in this case, message construction and delivery Wire Tap allows you to route messages to a separate location while they are being forwarded to the ultimate destination.
  • 20. avoid coupling <beans:bean id="bookingDao" class="example.SimpleBookingDao" /> <beans:bean id="bookingService" class="example.BookingService"> <beans:constructor-arg ref="bookingDao" /> </beans:bean> <channel id="mealPreferenceUpdatesChannel" /> <service-activator input-channel="mealPreferenceUpdatesChannel" output-channel="bookingEnrichedMealUpdates" ref="bookingService" method="populatePreference" /> <channel id="bookingEnrichedMealUpdates" /> <beans:bean id="updateRequestTransformer" class="example.MealPreferenceRequestTransformer" /> <service-activator input-channel="bookingEnrichedMealUpdates" output-channel="xmlMealUpdates" ref="updateRequestTransformer" method="buildMealPreferenceUpdateRequest" /> <channel id="xmlMealUpdates" /> <ws:outbound-gateway uri="http://example.com/mealupdates" request-channel="xmlMealUpdates" /> method invocations with message passing over channels Reducing coupling is one of the main concerns when integrating applications
  • 21. Event-driven architecture (EDA) is an architectural pattern in which complex applications are broken down into a set of components or services that interact via events Where events are communicated via channels that can act as buffers in periods of high throughput, such a system can be described as having a staged event driven architecture (SEDA). SEDA-based systems generally respond better to significant spikes in load than do standard multithreaded applications and are also easier to configure at runtime, for example, by modifying the number of consumers processing a certain event type. This allows for optimizations based on the actual requirements of the application, which in turn provides a better usage experience Spring Integration provides the building blocks to create both EDA and SEDA applications. Event-Driven Consumer pattern, but here the consumer is consuming messages rather than events - it’s just that the consumption is triggered by the event of a message becoming available. Event driven architecture
  • 22. Synchronous and asynchronous communication compared Traditionally, the integration between enterprise applications is based on message-driven, asynchronous mechanisms
  • 23. <channel id="input" /> <payload-type-router input-channel="input"> <mapping type="example.Order" channel="orders"/> <mapping type="example.Notification" channel="notifications"/> </payload-type-router> <channel id="orders" /> <channel id="notifications" /> <service-activator ref="ordersProcessor" input-channel="orders" output-channel="results" /> <service-activator ref="notificationsProcessor" input-channel="notifications" output-channel="results" /> <channel id="results" /> Spring Integration Way
  • 24. Spring Integration Way The structure doesn’t seem to tell what kind of interaction takes place (is it synchronous or asynchronous?)
  • 25. Spring Integration supports both approaches by using two different types of message channels DirectChannel (synchronous) and QueueChannel (asynchronous) Both types of channels are configured using the same <channel/> element. By default, its behavior is synchronous If you want to buffer the messages instead of passing them directly through a channel and to follow an asynchronous approach, you can use a queue to store them, like this <channel id="input"> <queue capacity="10"/> </channel> Spring Integration Way
  • 26. Message (Revisited) public interface Message<T> { MessageHeaders getHeaders(); T getPayload(); } public final class MessageHeaders implements Map<String, Object>, Serializable { /* implementation omitted */ } message headers are immutable to avoid issues with concurrency
  • 27. Channels public interface MessageChannel { boolean send(Message<?> message); boolean send(Message<?> message, long timeout); } it provides no methods for receiving messages
  • 28. Channels public interface SubscribableChannel extends MessageChannel { boolean subscribe(MessageHandler handler); boolean unsubscribe(MessageHandler handler); } I’ll let you know when I’ve got something! Do you have any messages for me? public interface PollableChannel extends MessageChannel { Message<?> receive(); Message<?> receive(long timeout); }
  • 29. Selecting right channel for the job In Spring Integration, the default channels are SubscribableChannels, and the message transmission is synchronous. So there is one thread and single transaction here <channel id="bookingConfirmationRequests"/> <service-activator input-channel="bookingConfirmationRequests" output-channel="chargedBookings" ref="billForBookingService" /> <channel id="chargedBookings" /> <service-activator input-channel="chargedBookings" output-channel="emailConfirmationRequests" ref="seatAvailabilityService" /> <channel id="emailConfirmationRequests" /> <outbound-channel-adapter channel="emailConfirmationRequests" ref="emailConfirmationService" />
  • 30. Email is slow and our servers are unreliable <channel id="emailConfirmationRequests"> <queue /> </channel> what if you need to connect one producer with not just one, but two (or more) consumers? Telling everyone who needs to know that a booking occured <service-activator input-channel="chargedBookings" output-channel="emailConfirmationRequests" ref="seatAvailabilityService" /> <publish-subscribe-channel id="completedBookings" /> <bridge input-channel="completedBookings" output-channel="emailConfirmationRequests" /> <channel id="emailConfirmationRequests"> <queue /> </channel>
  • 31. Some customers are more equal than others <channel id="bookingConfirmationRequests"> <priority-queue comparator="customerPriorityComparator" /> </channel> this causes the framework to instantiate an instance of PriorityChannel you can provide an instance of a class implementing Comparator<Message<?>>
  • 32. Endpoints • Polling or event-driven • Inbound or outbound • Unidirectional or bidirectional • Internal or external
  • 33. References Spring Integration in Action, MARK FISHER, JONAS PARTNER, MARIUS BOGOEVICI, IWEIN FULD Spring Integration Zülfikar Karakaya