Pro Spring Integration · Vitria • 11 IBM MQSeries 11 SonicMQ 11 AxwayIntegrator •* Oracle...
Transcript of Pro Spring Integration · Vitria • 11 IBM MQSeries 11 SonicMQ 11 AxwayIntegrator •* Oracle...
Pro Spring Integration
Dr. Mark Lui
Mario GrayAndy Chan
Josh Long
Contents
Contents at a Glance iv
About the Authors xvi
About the Technical Reviewers xvii
Acknowledgments xviii
Introduction xix
Chapter 1: Enterprise Application integration Fundamentals 1
Integration of Data and Services Between Disparate Systems 1
Integration Between Information Silos 2
Integration Between Companies 2
Integration with Users 3
Challenges 3
Technology 3
People 4
Approaches 5
File Transfer 5
Shared Database 6
Remote Procedure Calls 6
Messaging 7
Event-Driven Architectures 8
SEDA (Staged Event-Driven Architecture) 8
EAI Architecture 9
Domination by Proprietary Solutions 10
webMethods (Active Software) 10
Tibco 11
Vitria • •«11
IBM MQSeries 11
SonicMQ 11
Axway Integrator •*
Oracle SOA Suite 11
Microsoft BizTalk -12
EAI Patterns 12
Spring Integration Framework 14
Summary ..••14
Chapter 2: Exploring the Alternatives 15
A Basic Example of Integration 16
Mule ESB 16
Philosophy and Approach .16
Implementing the Integration Example 16
ServiceMix ....21
Philosophy and Approach.. 21
Implementing the Integration Example 21
OpenESB (GlassFish) ...30
Philosophy and Approach 30
Implementing the Integration Example 30
DIY Architecture, or How Not to Do an Integration 50
Philosophy and Approach 50
Implementing the Integration Example 50
How Do They Compare? 59
Ease of Use 59
Maintainability 59
Extensibility 60
Summary .60
Chapter 3: Introduction to Core Spring Framework 61
Core Spring API Components 61
The Inversion of Control Container 61
Spring Container Metadata Configuration 62
Multiple Configuration Resources 63
Instantiating the loC Container 63
Bean Instantiation from the loC Container 64
Constructor Injection 65
Bean References and Setter Injection 65
Static and Instance Factory Injection 65
Bean Scopes .67
Customizing Bean Initialization and Disposal 70
Simplifying Configuration with Bean Autowiring 71
Autowiring Beans byType 72
Autowiring Beans by Annotation 73
Differentiating Auto-Wired Beans 75
Autowiring by Name 77
Automatically Discovering Beans on the Classpath 77
Further Reducing XML with JavaConfiguration 79
Making Beans Aware of the Container 81
Externalizing Bean Property Values 82
Internationalization (i18n) Using MessageSource 83
Aspect-Oriented Framework 85
Aspect-Oriented Programming with AspectJ 85
Declaring Aspects with AspectJ Annotations 87
Defining Advice Order 89
Introducing Behaviors to Your Beans 91
Writing Custom Spring Namespaces 93
Writing the Namespace Handler 95
The Spring Expression Language 97
Features of the Language Syntax 97
Uses of the Language in Your Configurations 99
Summary 101
Chapter 4: Introduction to Enterprise Spring ....103
Data Access Framework 103
Selecting a Relational Model 104
Configuring an Embedded Data Source 105
Configuring a Remote Data Source 106
Basic JdbcTemplate Usages • 107
JdbcTemplate Callback Interfaces 110
Using JdbcTemplate to Query 112
Integrating Hibernate 3 and Spring 114
Configuring a Hibernate SessionFactory 116
The Hibernate Template 117
Persistence with Hibernate in a JPA Context 119
Configuration and Usage of JpaTemplate 121
Using JPA EntityManagers Directly 125
Transaction Management Framework 128
Spring Transaction Management 129
Controlling Transaction Propagation with the TransactionStatus Interface 130
Introduction to PlatformTransactionManager and Implementations , 131
Setting Up Transaction Control with TransactionTemplate 131
Declaring Transactions with Transaction Advices 134
Declarative Transaction Managing with the ©Transactional Annotation 138
Spring Remoting 142
Exposing and Invoking Services with RMI 143
Summary 148
Chapter 5: Introduction to Spring Integration.. 149
Spring Integration Basics 149
History 149
Familiar Spring Idioms 150
Low Coupling, High Productivity 150
Messages 150
Message Channels 151
Message Endpoints 151
Event-Driven Architecture 152
First Steps for Spring Integration 152
How to Set Up Your IDE 153
Starting Your First Spring Integration Project 154
Using Spring Roo to Bootstrap Your Project 159
Using SpringSource Tool Suite's Visual Support 159
Playing Well With Others 173
Spring Batch,
173
Spring BlazeDS 173
Summary 173
Chapter 6: Channels 175
EAI Message Channel Patterns 175
Point-to-Point Channel 176
Publlsh-Subscribe Channel 176
Data-Typed Channel 176
Invalid Message Channel 177
Dead Letter Channel 178
Channel Adapter 178
Messaging Bridge 178
Message Bus 179
Guaranteed Delivery 179
Choosing a Channel Instance 179
Point-to-Point Channel 181
Publish-Subscribe Channel 205
Channel Interceptors 205
MessagingTemplate 206
Configuring a Message Channel 210
QueueChannel 210
PriorityChannel... 210
RendezvousChannel 211
DirectChannel 211
ExecutorChannel 212
PublishSubscribeChannel 212
Channellnterceptor 212
Backing Up a Channel 213
Summary 215
Chapter 7: Transformations and Enrichment 217
The Canonical Data Model Concept 218
Spring Integration Transformer 220
Transforming a Message 220
Built-in Transformers 223
Leveraging Transformations in Integration 233
Header Enrichers 237
Message Mappers: Moving Transformation into the Framework 240
Method-Mapping Transformation 240
ConversionService 242
Summary 242
Chapter 8: Message Flow: Routing and Filtering 245
Message Flow Patterns 245
Router 246
Filter 246
Splitter 246
Aggregator 246
Resequencer 246
Message Flows Using Spring Integration 246
Filters 254
Splitter 260
Aggregator 264
Message Handler Chain 275
Message Bridge 276
Workflow 277
Software Processes 278
Introducing Activiti, an Apache 2 Licensed BPMN 2 Engine 281
Configuring Activiti with Spring 282
The Spring Integration Inbound Activiti Gateway 286
Summary 290
Chapter 9: Endpoints and Adapters 291
Messaging Endpoint API 291
Polling and Event-Driven Consumers 291
Message Assignment vs. Message Grab 291
Synchronous and Asynchronous Services 292
Polling Consumers 293
Event-Driven Consumers 300
ConsumerEndpointFactoryBean 302
Service Activator 305
Spring Integration Adapters 308
File System Adapters 308
Database (JDBC) Adapters 308
JMS Adapters 308
Web Services Adapters 309
Custom Adapters 309
Configuring an Adapter Through the XML Namespace 309
Configuring Adapters with STS 311
Messaging Gateways 316
Spring Integration Support for Gateways 317
Asynchronous Gateways 320
Gateways Receiving No Response 321
Inbound/Outbound Gateways via JMS 322
Secure Channels 325
Summary 328
Chapter 10: Monitoring and Management 329
Error Handling 329
History in EAI and MOM: The Dead Letter Queue 330
The Error Channel in Spring Integration 330
JMX 333
Basic Monitoring for Your Application 334
Exposing Your Services Through JMX 343
Measuring Performance 346
Hyperic 352
Wire Tap 355
Message History 356
Control Bus 358
Summary 360
Chapter 11: Talking to the Metal 361
File System Integration 361
File Adapter 361
Native Event File Adapter 367
TCP and UDP Integration 367
Stream Processing 373
Stdin and Stdout 374
Following a Log File 375
FTP/FTPS and SFTP 376
FTP 376
SFTP 381
Spring Integration's Remote File System Abstractions 385
Spring Integration's File System Abstractions 387
JDBC 387
JDBC Inbound Channel Adapter 388
JDBC Outbound Channel Adapter 391
JDBC Outbound Gateway 393
Summary 396
Chapter 12: Enterprise Messaging with JMS and AMQP 397
JMS Integration 397
JMS Brokers 398
JMS Channel Adapters 415
JMS Gateway 427
JMS-Backed Message Channel 428
AMQP Integration 434
SpringSource RabbitMQ 436
Apache Qpid 444
Other Messaging Systems 449
Amazon SQS 449
Kestrel MQ 450
Kafka 450
Summary ..450
Chapter 13: Social Messaging 451
E-mail 451
IMAP and IMAP-IDLE 452
P0P3 455
SMTP 457
XMPP 459
Twitter 466
News Feed 474
Summary 476
Chapter 14: Web Services 477
Maven Dependencies 477
XML Schema 478
Configuring a Web Services Inbound Gateway 479
Configuring Web Services Endpoints 481
Payload Extraction with DOM 481
Invoking Web Services Using an Outbound Gateway 483
Web Services and XML Marshalling 485
WSDL Options 492
Outbound Web Services Gateway with XML Marshalling 496
Summary 498
Chapter 15: Extending Spring Integration 499
Inbound Adapters 500
Writing an Event-Driven Adapter 5O0
Writing a Polling Adapter 511
Outbound Adapters 515
Packaging Your Adapters for Reuse 519
Building a Namespace for the File System Monitoring Adapter 521
Building a Namespace for the Polling Adapter 523
Building a Namespace for the Outbound Channel Adapter 526
Summary 528
Chapter 16: Scaling Your Spring Integration Application 529
Introducing Scalability 529
Concurrency 531
JavaSE 531
Java EE 534
Spring Framework 534
Scaling the Middleware 541
Message Broker 541
Web Services 544
Database 546
Scaling State in Spring Integration 547
Claim Check Pattern 547
MessageGroupStore 550
Summary 559
Chapter 17: Spring Integration and Spring Batch 561
What Is Spring Batch? 561
Setting Up Spring Batch 564
Reading and Writing 567
Retry 573
Transaction and Rollback 573
Concurrency 574
Launching a Job 575
Event-Driven Batch Processing 577
Launching Jobs with Spring Integration 577
Partitioning 580
Spring Batch Admin 585
Summary 589
Chapter 18: Spring Integration and Your Web Application 591
HTTP Adapters and Gateways 591
HTTP Adapter and Gateway Namespace Support 593
HTTP Adapter and Gateway Example 594
Multipart Support 598
Spring Integration, Comet, and the Asynchronous Web 601
Spring Integration, Flex, and BlazeDS 607
Summary 614
Index:> - • • »615