4. Integration Styles
• Business to Business Integration (B2B)
• Inter Application Integration (EAI)
• Intra Application Integration
4
JVM JVM
EAI
External Business
Partner
B2B
Core Messaging
Tuesday, December 18, 12
5. Integration Styles
• File Transfer
• Shared Database
• Remoting
• Messaging
5
Tuesday, December 18, 12
7. Enterprise Integration Patterns
• By Gregor Hohpe & Bobby Woolf
• Published 2003
• Collection of well-known patterns
• http://www.eaipatterns.com/eaipatterns.html
7
Tuesday, December 18, 12
8. 8
“Spring Integration provides an extension
of the Spring programming model
to support the well-known enterprise
integration patterns.
Tuesday, December 18, 12
9. What is Spring Integration?
• Light-weight messaging framework
• Provides an adapter-based platform for communicating with external
systems
• Pipes and Filters at the core of Spring Integration’s architecture
–Endpoint (Filter)
–Channel (Pipe)
–Message
9
Tuesday, December 18, 12
10. Advantages
• Provides building blocks to implement systems that are:
– are loosely Coupled (Logically or Physically)
– are Event Driven (EDA)
– have a staged event-driven architecture (SEDA)
• Sophisticated support for synchronous / asynchronous messaging
10
Tuesday, December 18, 12
13. What is in a Message?
• Unit of information
• Encapsulates data
• Passed between endpoints
• Consists of headers
– contains data relevant to the messaging system
• and a payload
– actual data for the receiver
– depending on use-cases: POJO instances or serialized data
13
Tuesday, December 18, 12
14. What is in a Message?
14
package org.springframework.integration;
public interface Message<T> {
MessageHeaders getHeaders();
T getPayload();
}
Tuesday, December 18, 12
15. Message Headers
• Message ID (automatically generated UUID)
• Timestamp
• Correlation Id
• Reply Channel
• Error Channel
• Expiration Date
• Priority
• ...
• Add your own headers using a Header Enricher
15
Tuesday, December 18, 12
16. Function of a Message
• Command Message
• Event Message
• Document Message
16
E
D
C
Tuesday, December 18, 12
17. What is a Channel?
• Channels connect producers and consumers (decoupling)
• MessageChannel Interface:
–PollableChannel (Polling Consumer)
–SubscribableChannel (Event Driven)
• Implementations:
–DirectChannel
–PublishSubscribeChannel
–QueueChannel
–PriorityChannel
–RendezvousChannel
–ExecutorChannel
17
<int:channel id="input">
<int:queue capacity="10"/>
</int:channel>
Tuesday, December 18, 12
18. What is an Endpoint?
• Polling or event-driven
• Inbound or outbound
• Unidirectional (Channel Adapter) or bidirectional (Gateway)
• Internal or external (application context)
18
<inbound-channel-adapter/>
<outbound-channel-adapter/>
<inbound-gateway/>
<outbound-gateway/>
<gateway/>
<service-activator/>
Tuesday, December 18, 12
19. Router
• Message Router
• Content-based router
• Recipient list router (with selectors)
• Payload type router
• Header value router
• Exception type router
19
Tuesday, December 18, 12
20. Transformer
• Delegating via ref/method
• Spring Expression Language
• Groovy, JRuby, Jython, JavaScript
• Object-to-JSON / JSON-to-Object
• Payload serializing/deserializing
• File-to-bytes, File-to-String
• JAXB, JibX, Castor, XMLBeans, Xstream
• XPath, XSLT
• Object XML Marshalling/Unmarshalling (Spring OXM)
• ...
20
Tuesday, December 18, 12
21. Spring Integration Components
21
• Claim Check (In/Out)
• Content Enricher
–Header Enricher
–Payload Enricher
• Control Bus
• Delayer
• JMX Support
• Message Handler Chain
• Messaging Bridge
• Resequencer
• Service Activator
• Scripting support (JSR 223)
– Ruby/JRuby, Javascript ...
• Groovy
• Message History
• Message Store
– JDBC, Redis, MongoDB,
Gemfire
• Wire Tap
• ...
Tuesday, December 18, 12
30. 30
Batch Jobs
Differ from online/real-time processing applications:
• Long-running
– Often outside office hours
• Non-interactive
– Often include logic for handling errors or restarts
• Process large volumes of data
– More than fits in memory or a single transaction
Tuesday, December 18, 12
31. Batch and offline processing
• Close of business processing
– Order processing
– Business reporting
– Account reconciliation
• Import/export handling
– a.k.a. ETL jobs (Extract-Transform-Load)
– Instrument/position import
– Data warehouse synchronization
• Large-scale output jobs
– Loyalty scheme emails
– Bank statements
• 31
Tuesday, December 18, 12
33. Chunk-Oriented Processing
• Input-output can be grouped together
• Input collects Items before outputting:Chunk-Oriented Processing
• Optional ItemProcessor
33
Tuesday, December 18, 12
36. More Complex Use Cases
• It's very common to use an off-the-shelf reader
and writer
• More complex jobs often require custom readers
or writers
• ItemProcessor is often used if there's a need to
delegate to existing business logic
• Use a writer if it's more efficient to process a
complete chunk
36
Tuesday, December 18, 12
37. Job and Step in Context
37
Tuesday, December 18, 12
39. ExecutionContext
• We need to know where a failure occurred to restart a batch
process
• Job Repository metadata is used to determine the step at
which the failure occurred
• Application Code (in reader/writer) needs to maintain state
within a step (e.g. current chunk)
• Spring Batch can supply that data during restart to facilitate
repositioning
39
Tuesday, December 18, 12
40. Common Batch Idioms
• Batch jobs typically process large amounts of homogeneous
input
• Makes iteration a common concern: Repeat
• Transient errors during processing may require a Retry of
an input item
• Some input may not be valid, may want to Skip it without
failing
• Some errors should fail the job execution, allowing one to fix
the problem and Restart the job instance where it left off
40
Tuesday, December 18, 12
41. Spring Batch
• Spring Batch supports these common concerns
• Abstracts them in the framework
– Job business logic doesn't need to care about details
• Allows for simple configuration with pluggable strategies
41
Tuesday, December 18, 12
43. Spring Batch Admin
• Sub project of Spring Batch
• Provides Web UI and ReSTFul interface to manage batch
processes
• Manager, Resources, Sample WAR
– Deployed with batch job(s) as single app to be able to control &
monitor jobs
– Or monitors external jobs only via shared database
43
Tuesday, December 18, 12
44. Scaling and Parallel Processing
• First Rule:
– Use the simplest technique to get the job done in the required
time
– Do not optimize/parallelize unnecessarily
• Options:
– Multi-threaded Step (single process)
– Parallel Steps (single process)
– Remote Chunking of Step (multi process)
– Partitioning a Step (single or multi process)
44
Tuesday, December 18, 12
46. Launching batch jobs through messages
• Event-Driven execution of the JobLauncher
• Spring Integration retrieves the data (e.g. file system, FTP, ...)
• Easy to support separate input sources simultaneously
46
D
C
FTP
Inbound Channel Adapter
JobLauncher
Transformer
File
JobLaunchRequest
Tuesday, December 18, 12
47. Providing feedback with informational messages
• Spring Batch provides support for listeners:
– StepListener
– ChunkListener
– JobExecutionListener
47
<batch:job
id="importPayments">
...
<batch:listeners>
<batch:listener
ref="notificationExecutionsListener"/>
</batch:listeners>
</batch:job>
<int:gateway
id="notificationExecutionsListener"
service-‐interface="o.s.batch.core.JobExecutionListener"
default-‐request-‐channel="jobExecutions"/>
Tuesday, December 18, 12
48. Externalizing batch process execution
• Use Spring Integration inside of Batch jobs, e.g.:
– ItemProcessor
– ItemWriter
• Offload complex processing
• Asynchronous processing support:
– AsyncItemProcessor
– AsyncItemWriter
• Externalize chunk processing using ChunkMessageChannelItemWriter
48
Tuesday, December 18, 12