+ All Categories
Home > Documents > Spring Integration Reference

Spring Integration Reference

Date post: 19-Oct-2015
Category:
Upload: ramesh-reddy
View: 180 times
Download: 4 times
Share this document with a friend
Popular Tags:

of 364

Transcript
  • Spring Integration Reference Manual

    Mark FisherMarius Bogoevici

    Iwein FuldJonas Partner

    Oleg ZhurakouskyGary Russell

    Dave SyerJosh Long

    David TuranskiGunnar HillertArtem BilanAmol Nayak

  • Spring Integration Reference Manualby Mark Fisher, Marius Bogoevici, Iwein Fuld, Jonas Partner, Oleg Zhurakousky, Gary Russell, Dave Syer, JoshLong, David Turanski, Gunnar Hillert, Artem Bilan, and Amol Nayak

    2.2.4.RELEASECopyright 2009, 2010, 2011, 2012 VMware, Inc. All rights reserved. VMware is a registered trademark ortrademark of VMware, Inc. in the United States and/or other jurisdictions. All other marks and names mentionedherein may be trademarks of their respective companies.

  • Spring Integration

    2.2.4.RELEASESpring IntegrationReference Manual iii

    Table of ContentsPreface ..................................................................................................................................... xv

    1. Code Conventions ........................................................................................................ xvI. What's new? ........................................................................................................................... 1

    1. What's new in Spring Integration 2.2? ............................................................................. 21.1. New Components ................................................................................................ 2

    RedisStore Inbound and Outbound Channel Adapters ........................................... 2MongoDB Inbound and Outbound Channel Adapters ........................................... 2JPA Endpoints ................................................................................................... 2

    1.2. General Changes ................................................................................................. 2Spring 3.1 Used by Default ................................................................................ 2Adding Behavior to Endpoints ............................................................................ 2Transaction Synchronization and Pseudo Transactions .......................................... 3File Adapter - Improved File Overwrite/Append Handling .................................... 3Reply-Timeout added to more Outbound Gateways .............................................. 3Spring-AMQP 1.1 .............................................................................................. 3JDBC Support - Stored Procedures Components .................................................. 4JDBC Support - Outbound Gateway .................................................................... 4JDBC Support - Channel-specific Message Store Implementation .......................... 4Orderly Shutdown .............................................................................................. 4JMS Oubound Gateway Improvements ................................................................ 5object-to-json-transformer ................................................................................... 5HTTP Support ................................................................................................... 5JDBC Message Store Improvements .................................................................... 5

    II. Overview of Spring Integration Framework ............................................................................ 62. Spring Integration Overview ........................................................................................... 7

    2.1. Background ......................................................................................................... 72.2. Goals and Principles ............................................................................................ 72.3. Main Components ............................................................................................... 8

    Message ............................................................................................................. 8Message Channel ............................................................................................... 9Message Endpoint .............................................................................................. 9

    2.4. Message Endpoints ............................................................................................ 10Transformer ..................................................................................................... 10Filter ................................................................................................................ 10Router .............................................................................................................. 10Splitter ............................................................................................................. 11Aggregator ....................................................................................................... 11Service Activator .............................................................................................. 11Channel Adapter .............................................................................................. 12

    III. Core Messaging .................................................................................................................. 133. Messaging Channels ..................................................................................................... 14

    3.1. Message Channels ............................................................................................. 14The MessageChannel Interface .......................................................................... 14

  • Spring Integration

    2.2.4.RELEASESpring IntegrationReference Manual iv

    PollableChannel ....................................................................................... 14SubscribableChannel ................................................................................. 14

    Message Channel Implementations .................................................................... 15PublishSubscribeChannel .......................................................................... 15QueueChannel .......................................................................................... 15PriorityChannel ........................................................................................ 15RendezvousChannel .................................................................................. 15DirectChannel .......................................................................................... 16ExecutorChannel ...................................................................................... 17Scoped Channel ....................................................................................... 18

    Channel Interceptors ......................................................................................... 18MessagingTemplate .......................................................................................... 20Configuring Message Channels ......................................................................... 20

    DirectChannel Configuration ..................................................................... 21Datatype Channel Configuration ................................................................ 21QueueChannel Configuration .................................................................... 22PublishSubscribeChannel Configuration ..................................................... 23ExecutorChannel ...................................................................................... 24PriorityChannel Configuration ................................................................... 24RendezvousChannel Configuration ............................................................ 24Scoped Channel Configuration .................................................................. 25Channel Interceptor Configuration ............................................................. 25Global Channel Interceptor ....................................................................... 25Wire Tap ................................................................................................. 26Global Wire Tap Configuration ................................................................. 27

    Special Channels .............................................................................................. 283.2. Poller (Polling Consumer) .................................................................................. 283.3. Channel Adapter ................................................................................................ 29

    Configuring An Inbound Channel Adapter ......................................................... 29Configuring Outbound Channel Adapter ............................................................ 30

    3.4. Messaging Bridge .............................................................................................. 31Introduction ...................................................................................................... 31Configuring Bridge ........................................................................................... 32

    4. Message Construction ................................................................................................... 334.1. Message ............................................................................................................ 33

    The Message Interface ...................................................................................... 33Message Headers .............................................................................................. 33Message Implementations ................................................................................. 34The MessageBuilder Helper Class ..................................................................... 35

    5. Message Routing .......................................................................................................... 375.1. Routers ............................................................................................................. 37

    Overview ......................................................................................................... 37Common Router Parameters ............................................................................. 39

    Inside and Outside of a Chain ................................................................... 39Top-Level (Outside of a Chain) ................................................................ 40

  • Spring Integration

    2.2.4.RELEASESpring IntegrationReference Manual v

    Router Implementations .................................................................................... 41PayloadTypeRouter .................................................................................. 41HeaderValueRouter .................................................................................. 41RecipientListRouter .................................................................................. 42XPath Router ........................................................................................... 43Routing and Error handling ....................................................................... 43

    Configuring (Generic) Router ........................................................................... 44Configuring a Content Based Router with XML ......................................... 44Configuring a Router with Annotations ..................................................... 46

    Dynamic Routers .............................................................................................. 46Manage Router Mappings using the Control Bus ........................................ 49Manage Router Mappings using JMX ........................................................ 49

    5.2. Filter ................................................................................................................. 50Introduction ...................................................................................................... 50Configuring Filter ............................................................................................. 50

    Configuring a Filter with XML ................................................................. 50Configuring a Filter with Annotations ....................................................... 52

    5.3. Splitter .............................................................................................................. 53Introduction ...................................................................................................... 53Programming model ......................................................................................... 53Configuring Splitter .......................................................................................... 54

    Configuring a Splitter using XML ............................................................. 54Configuring a Splitter with Annotations ..................................................... 55

    5.4. Aggregator ........................................................................................................ 55Introduction ...................................................................................................... 55Functionality .................................................................................................... 55Programming model ......................................................................................... 55

    AggregatingMessageHandler ..................................................................... 56ReleaseStrategy ........................................................................................ 57CorrelationStrategy ................................................................................... 59

    Configuring an Aggregator ............................................................................... 59Configuring an Aggregator with XML ....................................................... 59Configuring an Aggregator with Annotations ............................................. 63

    Managing State in an Aggregator: MessageGroupStore ....................................... 645.5. Resequencer ...................................................................................................... 66

    Introduction ...................................................................................................... 66Functionality .................................................................................................... 66Configuring a Resequencer ............................................................................... 66

    5.6. Message Handler Chain ..................................................................................... 67Introduction ...................................................................................................... 67Configuring Chain ............................................................................................ 68

    6. Message Transformation ............................................................................................... 716.1. Transformer ....................................................................................................... 71

    Introduction ...................................................................................................... 71Configuring Transformer .................................................................................. 71

  • Spring Integration

    2.2.4.RELEASESpring IntegrationReference Manual vi

    Configuring Transformer with XML .......................................................... 71Configuring a Transformer with Annotations ............................................. 76

    Header Filter .................................................................................................... 766.2. Content Enricher ............................................................................................... 77

    Introduction ...................................................................................................... 77Header Enricher ............................................................................................... 77Payload Enricher .............................................................................................. 79

    Configuration ........................................................................................... 79Examples ................................................................................................. 81

    6.3. Claim Check ..................................................................................................... 82Introduction ...................................................................................................... 82Incoming Claim Check Transformer .................................................................. 82Outgoing Claim Check Transformer .................................................................. 84A word on Message Store ................................................................................ 85

    7. Messaging Endpoints .................................................................................................... 867.1. Message Endpoints ............................................................................................ 86

    Message Handler .............................................................................................. 86Event Driven Consumer ................................................................................... 87Polling Consumer ............................................................................................. 87Namespace Support .......................................................................................... 89Change Polling Rate at Runtime ....................................................................... 93Payload Type Conversion ................................................................................. 94Asynchronous polling ....................................................................................... 94

    7.2. Messaging Gateways ......................................................................................... 95Enter the GatewayProxyFactoryBean ................................................................. 95Gateway XML Namespace Support ................................................................... 95Setting the Default Reply Channel .................................................................... 96Gateway Configuration with Annotations and/or XML ....................................... 96Invoking No-Argument Methods ....................................................................... 97Error Handling ................................................................................................ 98Asynchronous Gateway .................................................................................... 99Gateway behavior when no response arrives .................................................... 100

    7.3. Service Activator ............................................................................................. 102Introduction .................................................................................................... 102Configuring Service Activator ......................................................................... 102

    7.4. Delayer ........................................................................................................... 104Introduction .................................................................................................... 104Configuring Delayer ....................................................................................... 104Delayer and Message Store ............................................................................. 105

    7.5. Scripting support ............................................................................................. 106Script configuration ........................................................................................ 107

    7.6. Groovy support ................................................................................................ 109Groovy configuration ...................................................................................... 109Control Bus .................................................................................................... 110

    7.7. Adding Behavior to Endpoints .......................................................................... 110

  • Spring Integration

    2.2.4.RELEASESpring IntegrationReference Manual vii

    Provided Advice Classes ................................................................................. 111Retry Advice .......................................................................................... 111Circuit Breaker Advice ........................................................................... 115Expression Evaluating Advice ................................................................. 116

    Custom Advice Classes .................................................................................. 1178. System Management ................................................................................................... 119

    8.1. JMX Support ................................................................................................... 119Notification Listening Channel Adapter ........................................................... 119Notification Publishing Channel Adapter ......................................................... 120Attribute Polling Channel Adapter ................................................................... 120Operation Invoking Channel Adapter ............................................................... 121Operation Invoking Outbound Gateway ........................................................... 121MBean Exporter ............................................................................................. 121

    MBean ObjectNames .............................................................................. 122MessageChannel MBean Features ............................................................ 123Orderly Shutdown Managed Operation .................................................... 124

    8.2. Message History .............................................................................................. 124Message History Configuration ....................................................................... 124

    8.3. Message Store ................................................................................................. 1258.4. Control Bus ..................................................................................................... 1278.5. Orderly Shutdown ............................................................................................ 128

    IV. Integration Adapters ......................................................................................................... 1299. AMQP Support .......................................................................................................... 130

    9.1. Introduction ..................................................................................................... 1309.2. Inbound Channel Adapter ................................................................................. 1309.3. Outbound Channel Adapter .............................................................................. 1339.4. Inbound Gateway ............................................................................................. 1349.5. Outbound Gateway .......................................................................................... 1359.6. AMQP Backed Message Channels .................................................................... 1369.7. AMQP Message Headers ................................................................................. 1369.8. AMQP Samples ............................................................................................... 138

    10. Spring ApplicationEvent Support ............................................................................... 13910.1. Receiving Spring ApplicationEvents ............................................................... 13910.2. Sending Spring ApplicationEvents .................................................................. 139

    11. Feed Adapter ............................................................................................................ 14111.1. Introduction ................................................................................................... 14111.2. Feed Inbound Channel Adapter ....................................................................... 141

    12. File Support ............................................................................................................. 14312.1. Introduction ................................................................................................... 14312.2. Reading Files ................................................................................................. 14312.3. Writing files .................................................................................................. 145

    Specifying the Output Directory ...................................................................... 145Dealing with Existing Destination Files ........................................................... 146File Outbound Channel Adapter ...................................................................... 147Outbound Gateway ......................................................................................... 147

  • Spring Integration

    2.2.4.RELEASESpring IntegrationReference Manual viii

    12.4. File Transformers ........................................................................................... 14813. FTP/FTPS Adapters .................................................................................................. 149

    13.1. Introduction ................................................................................................... 14913.2. FTP Session Factory ...................................................................................... 14913.3. FTP Inbound Channel Adapter ....................................................................... 15113.4. FTP Outbound Channel Adapter ..................................................................... 15313.5. FTP Outbound Gateway ................................................................................. 15413.6. FTP Session Caching ..................................................................................... 156

    14. GemFire Support ...................................................................................................... 15714.1. Introduction ................................................................................................... 15714.2. Inbound Channel Adapter ............................................................................... 15714.3. Continuous Query Inbound Channel Adapter ................................................... 15814.4. Outbound Channel Adapter ............................................................................ 15914.5. Gemfire Message Store .................................................................................. 159

    15. HTTP Support .......................................................................................................... 16115.1. Introduction ................................................................................................... 16115.2. Http Inbound Gateway ................................................................................... 16115.3. Http Outbound Gateway ................................................................................. 16215.4. HTTP Namespace Support ............................................................................. 16315.5. Timeout Handling .......................................................................................... 16715.6. HTTP Proxy configuration ............................................................................. 16915.7. HTTP Header Mappings ................................................................................. 17015.8. HTTP Samples .............................................................................................. 171

    Multipart HTTP request - RestTemplate (client) and Http Inbound Gateway(server) .......................................................................................................... 171

    16. TCP and UDP Support ............................................................................................. 17316.1. Introduction ................................................................................................... 17316.2. UDP Adapters ............................................................................................... 17316.3. TCP Connection Factories .............................................................................. 175

    TCP Caching Client Connection Factory .......................................................... 178TCP Failover Client Connection Factory .......................................................... 178

    16.4. TCP Connection Interceptors .......................................................................... 17916.5. TCP Adapters ................................................................................................ 18016.6. TCP Gateways ............................................................................................... 18116.7. TCP Message Correlation ............................................................................... 182

    Overview ....................................................................................................... 182Gateways ....................................................................................................... 183Collaborating Outbound and Inbound Channel Adapters ................................... 183

    16.8. A Note About NIO ........................................................................................ 18416.9. SSL/TLS Support ........................................................................................... 185

    Overview ....................................................................................................... 185Getting Started ............................................................................................... 185Advanced Techniques ..................................................................................... 186

    16.10. IP Configuration Attributes ........................................................................... 18717. JDBC Support .......................................................................................................... 195

  • Spring Integration

    2.2.4.RELEASESpring IntegrationReference Manual ix

    17.1. Inbound Channel Adapter ............................................................................... 195Polling and Transactions ................................................................................. 196Max-rows-per-poll versus Max-messages-per-poll ............................................ 196

    17.2. Outbound Channel Adapter ............................................................................ 19717.3. Outbound Gateway ........................................................................................ 19817.4. JDBC Message Store ..................................................................................... 199

    The Generic JDBC Message Store ................................................................... 199Backing Message Channels ............................................................................. 200Initializing the Database ................................................................................. 201Partitioning a Message Store ........................................................................... 202

    17.5. Stored Procedures .......................................................................................... 202Supported Databases ....................................................................................... 202Configuration ................................................................................................. 203Common Configuration Attributes ................................................................... 203Common Configuration Sub-Elements ............................................................. 205Defining Parameter Sources ............................................................................ 206Stored Procedure Inbound Channel Adapter ..................................................... 207Stored Procedure Outbound Channel Adapter ................................................... 208Stored Procedure Outbound Gateway ............................................................... 208Examples ....................................................................................................... 209

    18. JPA Support ............................................................................................................. 21118.1. Supported Persistence Providers ...................................................................... 21218.2. Java Implementation ...................................................................................... 21218.3. Namespace Support ........................................................................................ 213

    Common XML Namespace Configuration Attributes ........................................ 213Providing JPA Query Parameters ..................................................................... 215Transaction Handling ...................................................................................... 215

    18.4. Inbound Channel Adapter ............................................................................... 216Configuration Parameter Reference ................................................................. 217

    18.5. Outbound Channel Adapter ............................................................................ 218Using an Entity Class ..................................................................................... 218Using JPA Query Language (JPA QL) ............................................................ 218Using Native Queries ...................................................................................... 219Using Named Queries ..................................................................................... 220Configuration Parameter Reference ................................................................. 221

    18.6. Outbound Gateways ....................................................................................... 222Common Configuration Parameters ................................................................. 223Updating Outbound Gateway .......................................................................... 224Retrieving Outbound Gateway ........................................................................ 224JPA Outbound Gateway Samples .................................................................... 225

    19. JMS Support ............................................................................................................ 22819.1. Inbound Channel Adapter ............................................................................... 22819.2. Message-Driven Channel Adapter ................................................................... 22919.3. Outbound Channel Adapter ............................................................................ 23019.4. Inbound Gateway ........................................................................................... 230

  • Spring Integration

    2.2.4.RELEASESpring IntegrationReference Manual x

    19.5. Outbound Gateway ........................................................................................ 23119.6. Mapping Message Headers to/from JMS Message ............................................ 23319.7. Message Conversion, Marshalling and Unmarshalling ...................................... 23319.8. JMS Backed Message Channels ...................................................................... 23419.9. Using JMS Message Selectors ........................................................................ 23519.10. JMS Samples ............................................................................................... 235

    20. Mail Support ............................................................................................................ 23720.1. Mail-Sending Channel Adapter ....................................................................... 23720.2. Mail-Receiving Channel Adapter .................................................................... 23720.3. Mail Namespace Support ................................................................................ 23820.4. Email Message Filtering ................................................................................. 24120.5. Transaction Synchronization ........................................................................... 242

    21. MongoDb Support .................................................................................................... 24421.1. Introduction ................................................................................................... 24421.2. Connecting to MongoDb ................................................................................ 24421.3. MongoDB Message Store ............................................................................... 24521.4. MongoDB Inbound Channel Adapter .............................................................. 24521.5. MongoDB Outbound Channel Adapter ............................................................ 247

    22. Redis Support ........................................................................................................... 24922.1. Introduction ................................................................................................... 24922.2. Connecting to Redis ....................................................................................... 24922.3. Messaging with Redis .................................................................................... 250

    Redis Publish/Subscribe channel ..................................................................... 250Redis Inbound Channel Adapter ...................................................................... 251Redis Outbound Channel Adapter .................................................................... 251

    22.4. Redis Message Store ...................................................................................... 25222.5. RedisStore Inbound Channel Adapter .............................................................. 25222.6. RedisStore Outbound Channel Adapter ............................................................ 254

    23. Resource Support ...................................................................................................... 25623.1. Introduction ................................................................................................... 25623.2. Resource Inbound Channel Adapter ................................................................ 256

    24. RMI Support ............................................................................................................ 25824.1. Introduction ................................................................................................... 25824.2. Outbound RMI .............................................................................................. 25824.3. Inbound RMI ................................................................................................. 25824.4. RMI namespace support ................................................................................. 258

    25. SFTP Adapters ......................................................................................................... 26025.1. Introduction ................................................................................................... 26025.2. SFTP Session Factory .................................................................................... 260

    Configuration Properties ................................................................................. 26125.3. SFTP Session Caching ................................................................................... 26225.4. SFTP Inbound Channel Adapter ...................................................................... 26325.5. SFTP Outbound Channel Adapter ................................................................... 26425.6. SFTP Outbound Gateway ............................................................................... 26525.7. SFTP/JSCH Logging ...................................................................................... 267

  • Spring Integration

    2.2.4.RELEASESpring IntegrationReference Manual xi

    26. Stream Support ......................................................................................................... 26826.1. Introduction ................................................................................................... 26826.2. Reading from streams .................................................................................... 26826.3. Writing to streams ......................................................................................... 26826.4. Stream namespace support .............................................................................. 269

    27. Twitter Adapter ........................................................................................................ 27027.1. Introduction ................................................................................................... 27027.2. Twitter OAuth Configuration .......................................................................... 27027.3. Twitter Template ........................................................................................... 27127.4. Twitter Inbound Adapters ............................................................................... 271

    Inbound Message Channel Adapter .................................................................. 272Direct Inbound Message Channel Adapter ....................................................... 273Mentions Inbound Message Channel Adapter ................................................... 273Search Inbound Message Channel Adapter ....................................................... 273

    27.5. Twitter Outbound Adapter .............................................................................. 273Twitter Outbound Update Channel Adapter ...................................................... 274Twitter Outbound Direct Message Channel Adapter ......................................... 274

    28. Web Services Support ............................................................................................... 27628.1. Outbound Web Service Gateways ................................................................... 27628.2. Inbound Web Service Gateways ...................................................................... 27628.3. Web Service Namespace Support .................................................................... 27728.4. Outbound URI Configuration .......................................................................... 278

    29. XML Support - Dealing with XML Payloads ............................................................. 27929.1. Introduction ................................................................................................... 27929.2. Namespace Support ........................................................................................ 279

    XPath Expressions .......................................................................................... 280Providing Namespaces (Optional) to XPath Expressions ........................... 280Using XPath Expressions with Default Namespaces .................................. 281

    29.3. Transforming XML Payloads .......................................................................... 283Configuring Transformers as Beans ................................................................. 283

    UnmarshallingTransformer ...................................................................... 283MarshallingTransformer .......................................................................... 283XsltPayloadTransformer .......................................................................... 284ResultTransformers ................................................................................. 284

    Namespace Support for XML Transformers ..................................................... 285Namespace Configuration and ResultTransformers ........................................... 287

    29.4. Transforming XML Messages Using XPath ..................................................... 28829.5. Splitting XML Messages ................................................................................ 29029.6. Routing XML Messages Using XPath ............................................................. 291

    XML Payload Converter ................................................................................. 29229.7. XPath Header Enricher ................................................................................... 29329.8. Using the XPath Filter ................................................................................... 29329.9. XML Validating Filter ................................................................................... 295

    30. XMPP Support ......................................................................................................... 29730.1. Introduction ................................................................................................... 297

  • Spring Integration

    2.2.4.RELEASESpring IntegrationReference Manual xii

    30.2. XMPP Connection ......................................................................................... 29730.3. XMPP Messages ............................................................................................ 298

    Inbound Message Channel Adapter .................................................................. 298Outbound Message Channel Adapter ............................................................... 298

    30.4. XMPP Presence ............................................................................................. 299Inbound Presence Message Channel Adapter .................................................... 299Outbound Presence Message Channel Adapter ................................................. 299

    30.5. Appendices .................................................................................................... 300V. Appendices ........................................................................................................................ 302

    A. Message Publishing ................................................................................................... 303A.1. Message Publishing Configuration ................................................................... 303

    Annotation-driven approach via @Publisher annotation .................................... 303XML-based approach via the element ......................... 305Producing and publishing messages based on a scheduled trigger ....................... 307

    B. Transaction Support ................................................................................................... 309B.1. Understanding Transactions in Message flows ................................................... 309

    Poller Transaction Support .............................................................................. 310B.2. Transaction Boundaries ................................................................................... 311B.3. Transaction Synchronization ............................................................................ 312B.4. Pseudo Transactions ........................................................................................ 314

    C. Security in Spring Integration ..................................................................................... 315C.1. Introduction .................................................................................................... 315C.2. Securing channels ........................................................................................... 315

    D. Spring Integration Samples ........................................................................................ 317D.1. Introduction .................................................................................................... 317D.2. Where to get Samples ..................................................................................... 317D.3. Submitting Samples or Sample Requests .......................................................... 318D.4. Samples Structure ........................................................................................... 318D.5. Samples .......................................................................................................... 320

    Loan Broker ................................................................................................... 320The Cafe Sample ............................................................................................ 325The XML Messaging Sample .......................................................................... 329

    E. Configuration ............................................................................................................. 330E.1. Introduction ..................................................................................................... 330E.2. Namespace Support ......................................................................................... 330E.3. Configuring the Task Scheduler ....................................................................... 331E.4. Error Handling ................................................................................................ 332E.5. Annotation Support ......................................................................................... 333E.6. Message Mapping rules and conventions .......................................................... 336

    Simple Scenarios ............................................................................................ 336Complex Scenarios ......................................................................................... 338

    F. Additional Resources .................................................................................................. 341F.1. Spring Integration Home .................................................................................. 341

    G. Change History .......................................................................................................... 342G.1. Changes between 1.0 and 2.0 ........................................................................... 342

  • Spring Integration

    2.2.4.RELEASESpring IntegrationReference Manual xiii

    Spring 3 support ............................................................................................. 342Support for the Spring Expression Language (SpEL) ................................ 342ConversionService and Converter ............................................................ 342TaskScheduler and Trigger ...................................................................... 342RestTemplate and HttpMessageConverter ................................................ 342

    Enterprise Integration Pattern Additions ........................................................... 342Message History ..................................................................................... 343Message Store ........................................................................................ 343Claim Check .......................................................................................... 343Control Bus ............................................................................................ 343

    New Channel Adapters and Gateways ............................................................. 343TCP/UDP Adapters ................................................................................ 343Twitter Adapters ..................................................................................... 343XMPP Adapters ..................................................................................... 343FTP/FTPS Adapters ................................................................................ 344SFTP Adapters ....................................................................................... 344Feed Adapters ........................................................................................ 344

    Other Additions .............................................................................................. 344Groovy Support ...................................................................................... 344Map Transformers .................................................................................. 344JSON Transformers ................................................................................ 344Serialization Transformers ....................................................................... 344

    Framework Refactoring ................................................................................... 344New Source Control Management and Build Infrastructure ............................... 345New Spring Integration Samples ..................................................................... 345SpringSource Tool Suite Visual Editor for Spring Integration ............................ 345

    G.2. Changes between 2.0 and 2.1 ........................................................................... 345New Components ........................................................................................... 345

    JSR-223 Scripting Support ...................................................................... 345GemFire Support .................................................................................... 345AMQP Support ...................................................................................... 346MongoDB Support ................................................................................. 346Redis Support ......................................................................................... 346Support for Spring's Resource abstraction ................................................ 346Stored Procedure Components ................................................................. 346XPath and XML Validating Filter ........................................................... 347Payload Enricher .................................................................................... 347FTP and SFTP Outbound Gateways ........................................................ 347FTP Session Caching .............................................................................. 347

    Framework Refactoring ................................................................................... 348Standardizing Router Configuration ......................................................... 348XML Schemas updated to 2.1 ................................................................. 348

    Source Control Management and Build Infrastructure ....................................... 349Source Code now hosted on Github ......................................................... 349Improved Source Code Visibility with Sonar ............................................ 349

  • Spring Integration

    2.2.4.RELEASESpring IntegrationReference Manual xiv

    New Samples ................................................................................................. 349G.3. Changes between 2.1 and 2.2 ........................................................................... 349

  • Spring Integration

    2.2.4.RELEASESpring IntegrationReference Manual xv

    Preface1 Code ConventionsThe Spring Framework 2.0 introduced support for namespaces, which simplifies the Xml configurationof the application context, and consequently Spring Integration provides broad namespace support. Thisreference guide applies the following conventions for all code examples that use namespace support:

    The int namespace prefix will be used for Spring Integration's core namespace support. Each SpringIntegration adapter type (module) will provide its own namespace, which is configured using thefollowing convention:

    int- followed by the name of the module, e.g. int-twitter, int-stream,

    For a detailed explanation regarding Spring Integration's namespace support see Section E.2,Namespace Support.

    NotePlease note that the namespace prefix can be freely chosen. You may even choose not touse any namespace prefixes at all. Therefore, apply the convention that suits your applicationneeds best. Be aware, though, that SpringSource Tool Suite (STS) uses the same namespaceconventions for Spring Integration as used in this reference guide.

  • Part I. What's new?For those who are already familiar with Spring Integration, this chapter provides a brief overview of thenew features of version 2.2. If you are interested in the changes and features, that were introduced inearlier versions, please take a look at chapter: Appendix G, Change History

  • Spring Integration

    2.2.4.RELEASESpring IntegrationReference Manual 2

    1. What's new in Spring Integration 2.2?This chapter provides an overview of the new features and improvements that have been introduced withSpring Integration 2.2 If you are interested in even more detail, please take a look at the Issue Trackertickets that were resolved as part of the 2.2 development process:

    1.1 New ComponentsRedisStore Inbound and Outbound Channel Adapters

    Spring Integration now has RedisStore Inbound and Outbound Channel Adapters allowing you to writeand read Message payloads to/from Redis collection(s). For more information please see Section 22.6,RedisStore Outbound Channel Adapter and Section 22.5, RedisStore Inbound Channel Adapter.

    MongoDB Inbound and Outbound Channel AdaptersSpring Integration now has MongoDB Inbound and Outbound Channel Adapters allowing you to writeand read Message payloads to/from a MongoDB document store. For more information please seeSection 21.5, MongoDB Outbound Channel Adapter and Section 21.4, MongoDB Inbound ChannelAdapter.

    JPA Endpoints

    Spring Integration now includes components for the Java Persistence API (JPA) for retrieving andpersisting JPA entity objects. The JPA Adapter includes the following components:

    Inbound Channel Adapter

    Outbound Channel Adapter

    Updating Outbound Gateway

    Retrieving Outbound Gateway

    For more information please see Chapter 18, JPA Support

    1.2 General ChangesSpring 3.1 Used by DefaultSpring Integration now uses Spring 3.1.

    Adding Behavior to EndpointsThe ability to add an to a poller has been available for some time. However, the behavioradded by this affects the entire integration flow. It did not address the ability to add, say, retry, to anindividual endpoint. The 2.2. release introduces the to many endpoints.

    In addition, 3 standard Advice classes have been provided for this purpose:

  • Spring Integration

    2.2.4.RELEASESpring IntegrationReference Manual 3

    MessageHandlerRetryAdvice

    MessageHandlerCircuitBreakerAdvice

    ExpressionEvaluatingMessageHandlerAdvice

    For more information, see Section 7.7, Adding Behavior to Endpoints.

    Transaction Synchronization and Pseudo Transactions

    Pollers can now participate in Spring's Transaction Synchronization feature. This allows forsynchronizing such operations as renaming files by an inbound channel adapter depending on whetherthe transaction commits, or rolls back.

    In addition, these features can be enabled when there is not a 'real' transaction present, by means of aPseudoTransactionManager.

    For more information see Section B.3, Transaction Synchronization.

    File Adapter - Improved File Overwrite/Append HandlingWhen using the File Oubound Channel Adapter or the File Outbound Gateway, a new mode propertywas added. Prior to Spring Integration 2.2, target files were replaced when they existed. Now you canspecify the following options:

    REPLACE (Default)

    APPEND

    FAIL

    IGNORE

    For more information please see the section called Dealing with Existing Destination Files.

    Reply-Timeout added to more Outbound Gateways

    The XML Namespace support adds the reply-timeout attribute to the following Outbound Gateways:

    Amqp Outbound Gateway

    File Outbound Gateway

    Ftp Outbound Gateway

    Sftp Outbound Gateway

    Ws Outbound Gateway

    Spring-AMQP 1.1Spring Integration now uses Spring AMQP 1.1. This enables several features to be used within a SpringIntegration application, including...

  • Spring Integration

    2.2.4.RELEASESpring IntegrationReference Manual 4

    A fixed reply queue for the outbound gateway

    HA (mirrored) queues

    Publisher Confirms

    Returned Messages

    Support for Dead Letter Exchanges/Dead Letter Queues

    JDBC Support - Stored Procedures Components

    SpEL Support

    When using the Stored Procedure components of the Spring Integration JDBC Adapter, you can nowprovide Stored Procedure Names or Stored Function Names using Spring Expression Language (SpEL).

    This allows you to specify the Stored Procedures to be invoked at runtime. For example, you can provideStored Procedure names that you would like to execute via Message Headers. For more informationplease see Section 17.5, Stored Procedures.

    JMX Support

    The Stored Procedure components now provide basic JMX support, exposing some of their propertiesas MBeans:

    Stored Procedure Name

    Stored Procedure Name Expression

    JdbcCallOperations Cache Statistics

    JDBC Support - Outbound Gateway

    When using the JDBC Outbound Gateway, the update query is no longer mandatory. You can nowprovide solely a select query using the request message as a source of parameters.

    JDBC Support - Channel-specific Message Store Implementation

    A new Message Channel-specific Message Store Implementation has been added, providing a morescalable solution using database-specific SQL queries. For more information please see: the sectioncalled Backing Message Channels.

    Orderly Shutdown

    A method stopActiveComponents() has been added to the IntegrationMBeanExporter. Thisallows a Spring Integration application to be shut down in an orderly manner, disallowing new inboundmessages to certain adapters and waiting for some time to allow in-flight messages to complete.

  • Spring Integration

    2.2.4.RELEASESpring IntegrationReference Manual 5

    JMS Oubound Gateway Improvements

    The JMS Outbound Gateway can now be configured to use a MessageListener container to receivereplies. This can improve performance of the gateway.

    object-to-json-transformerThe ObjectToJsonTransformer now sets the content-type header to application/json by default.For more information see Section 6.1, Transformer.

    HTTP Support

    Java serialization over HTTP is no longer enabled by default. Previously, when setting a expected-response-type to a Serializable object, the Accept header was not properly setup. The SerializingHttpMessageConverter has now been updated to set the Acceptheader to application/x-java-serialized-object. However, because this could causeincompatibility with existing applications, it was decided to no longer automatically add this converterto the HTTP endpoints.

    If you wish to use Java serialization, you will need to add theSerializingHttpMessageConverter to the appropriate endpoints, using the message-converters attribute, when using XML configuration, or using the setMessageConverters()method.

    Alternatively, you may wish to consider using JSON instead which is enabled by simply havingJackson on the classpath.

    JDBC Message Store Improvements

    Spring Integration 2.2.4 adds a new set of DDL scripts for MySQL version 5.6.4 and higher. Now MySQLsupports fractional seconds and is thus improving the FIFO ordering when polling from a MySQL-basedMessage Store. For more information, please see the section called The Generic JDBC Message Store.

  • Part II. Overview of SpringIntegration Framework

    Spring Integration provides an extension of the Spring programming model to support the well-knownEnterprise Integration Patterns. It enables lightweight messaging within Spring-based applications andsupports integration with external systems via declarative adapters. Those adapters provide a higher-level of abstraction over Spring's support for remoting, messaging, and scheduling. Spring Integration'sprimary goal is to provide a simple model for building enterprise integration solutions while maintainingthe separation of concerns that is essential for producing maintainable, testable code.

  • Spring Integration

    2.2.4.RELEASESpring IntegrationReference Manual 7

    2. Spring Integration Overview2.1 BackgroundOne of the key themes of the Spring Framework is inversion of control. In its broadest sense, this meansthat the framework handles responsibilities on behalf of the components that are managed within itscontext. The components themselves are simplified since they are relieved of those responsibilities. Forexample, dependency injection relieves the components of the responsibility of locating or creating theirdependencies. Likewise, aspect-oriented programming relieves business components of generic cross-cutting concerns by modularizing them into reusable aspects. In each case, the end result is a systemthat is easier to test, understand, maintain, and extend.

    Furthermore, the Spring framework and portfolio provide a comprehensive programming model forbuilding enterprise applications. Developers benefit from the consistency of this model and especiallythe fact that it is based upon well-established best practices such as programming to interfaces andfavoring composition over inheritance. Spring's simplified abstractions and powerful support librariesboost developer productivity while simultaneously increasing the level of testability and portability.

    Spring Integration is motivated by these same goals and principles. It extends the Spring programmingmodel into the messaging domain and builds upon Spring's existing enterprise integration support toprovide an even higher level of abstraction. It supports message-driven architectures where inversion ofcontrol applies to runtime concerns, such as when certain business logic should execute and where theresponse should be sent. It supports routing and transformation of messages so that different transportsand different data formats can be integrated without impacting testability. In other words, the messagingand integration concerns are handled by the framework, so business components are further isolatedfrom the infrastructure and developers are relieved of complex integration responsibilities.

    As an extension of the Spring programming model, Spring Integration provides a wide variety ofconfiguration options including annotations, XML with namespace support, XML with generic "bean"elements, and of course direct usage of the underlying API. That API is based upon well-definedstrategy interfaces and non-invasive, delegating adapters. Spring Integration's design is inspired by therecognition of a strong affinity between common patterns within Spring and the well-known EnterpriseIntegration Patterns as described in the book of the same name by Gregor Hohpe and Bobby Woolf(Addison Wesley, 2004). Developers who have read that book should be immediately comfortable withthe Spring Integration concepts and terminology.

    2.2 Goals and PrinciplesSpring Integration is motivated by the following goals:

    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.

    Spring Integration is guided by the following principles:

  • Spring Integration

    2.2.4.RELEASESpring IntegrationReference Manual 8

    Components should be loosely coupled for modularity and testability.

    The framework should enforce separation of concerns between business logic and integration logic.

    Extension points should be abstract in nature but within well-defined boundaries to promote reuseand portability.

    2.3 Main ComponentsFrom the vertical perspective, a layered architecture facilitates separation of concerns, and interface-based contracts between layers promote loose coupling. Spring-based applications are typically designedthis way, and the Spring framework and portfolio provide a strong foundation for following this bestpractice for the full-stack of an enterprise application. Message-driven architectures add a horizontalperspective, yet these same goals are still relevant. Just as "layered architecture" is an extremely genericand abstract paradigm, messaging systems typically follow the similarly abstract "pipes-and-filters"model. The "filters" represent any component that is capable of producing and/or consuming messages,and the "pipes" transport the messages between filters so that the components themselves remainloosely-coupled. It is important to note that these two high-level paradigms are not mutually exclusive.The underlying messaging infrastructure that supports the "pipes" should still be encapsulated in a layerwhose contracts are defined as interfaces. Likewise, the "filters" themselves would typically be managedwithin a layer that is logically above the application's service layer, interacting with those servicesthrough interfaces much in the same way that a web-tier would.

    Message

    In Spring Integration, a Message is a generic wrapper for any Java object combined with metadata usedby the framework while handling that object. It consists of a payload and headers. The payload canbe of any type and the headers hold commonly required information such as id, timestamp, correlationid, and return address. Headers are also used for passing values to and from connected transports. Forexample, when creating a Message from a received File, the file name may be stored in a header to beaccessed by downstream components. Likewise, if a Message's content is ultimately going to be sentby an outbound Mail adapter, the various properties (to, from, cc, subject, etc.) may be configured asMessage header values by an upstream component. Developers can also store any arbitrary key-valuepairs in the headers.

  • Spring Integration

    2.2.4.RELEASESpring IntegrationReference Manual 9

    Message Channel

    A Message Channel represents the "pipe" of a pipes-and-filters architecture. Producers send Messages toa channel, and consumers receive Messages from a channel. The Message Channel therefore decouplesthe messaging components, and also provides a convenient point for interception and monitoring ofMessages.

    A Message Channel may follow either Point-to-Point or Publish/Subscribe semantics. With a Point-to-Point channel, at most one consumer can receive each Message sent to the channel. Publish/Subscribechannels, on the other hand, will attempt to broadcast each Message to all of its subscribers. SpringIntegration supports both of these.

    Whereas "Point-to-Point" and "Publish/Subscribe" define the two options for how many consumerswill ultimately receive each Message, there is another important consideration: should the channelbuffer messages? In Spring Integration, Pollable Channels are capable of buffering Messages withina queue. The advantage of buffering is that it allows for throttling the inbound Messages and therebyprevents overloading a consumer. However, as the name suggests, this also adds some complexity,since a consumer can only receive the Messages from such a channel if a poller is configured. On theother hand, a consumer connected to a Subscribable Channel is simply Message-driven. The variety ofchannel implementations available in Spring Integration will be discussed in detail in the section calledMessage Channel Implementations.

    Message Endpoint

    One of the primary goals of Spring Integration is to simplify the development of enterprise integrationsolutions through inversion of control. This means that you should not have to implement consumersand producers directly, and you should not even have to build Messages and invoke send or receiveoperations on a Message Channel. Instead, you should be able to focus on your specific domain modelwith an implementation based on plain Objects. Then, by providing declarative configuration, you can"connect" your domain-specific code to the messaging infrastructure provided by Spring Integration.The components responsible for these connections are Message Endpoints. This does not mean that youwill necessarily connect your existing application code directly. Any real-world enterprise integrationsolution will require some amount of code focused upon integration concerns such as routing andtransformation. The important thing is to achieve separation of concerns between such integration logicand business logic. In other words, as with the Model-View-Controller paradigm for web applications,the goal should be to provide a thin but dedicated layer that translates inbound requests into service layerinvocations, and then translates service layer return values into outbound replies. The next section willprovide an overview of the Message Endpoint types that handle these responsibilities, and in upcomingchapters, you will see how Spring Integration's declarative configuration options provide a non-invasiveway to use each of these.

  • Spring Integration

    2.2.4.RELEASESpring IntegrationReference Manual 10

    2.4 Message EndpointsA Message Endpoint represents the "filter" of a pipes-and-filters architecture. As mentioned above, theendpoint's primary role is to connect application code to the messaging framework and to do so in a non-invasive manner. In other words, the application code should ideally have no awareness of the Messageobjects or the Message Channels. This is similar to the role of a Controller in the MVC paradigm. Justas a Controller handles HTTP requests, the Message Endpoint handles Messages. Just as Controllers aremapped to URL patterns, Message Endpoints are mapped to Message Channels. The goal is the samein both cases: isolate application code from the infrastructure. These concepts are discussed at lengthalong with all of the patterns that follow in the Enterprise Integration Patterns book. Here, we provideonly a high-level description of the main endpoint types supported by Spring Integration and their roles.The chapters that follow will elaborate and provide sample code as well as configuration examples.

    Transformer

    A Message Transformer is responsible for converting a Message's content or structure and returning themodified Message. Probably the most common type of transformer is one that converts the payload ofthe Message from one format to another (e.g. from XML Document to java.lang.String). Similarly, atransformer may be used to add, remove, or modify the Message's header values.

    Filter

    A Message Filter determines whether a Message should be passed to an output channel at all. Thissimply requires a boolean test method that may check for a particular payload content type, a propertyvalue, the presence of a header, etc. If the Message is accepted, it is sent to the output channel, but ifnot it will be dropped (or for a more severe implementation, an Exception could be thrown). MessageFilters are often used in conjunction with a Publish Subscribe channel, where multiple consumers mayreceive the same Message and use the filter to narrow down the set of Messages to be processed basedon some criteria.

    NoteBe careful not to confuse the generic use of "filter" within the Pipes-and-Filters architecturalpattern with this specific endpoint type that selectively narrows down the Messages flowingbetween two channels. The Pipes-and-Filters concept of "filter" matches more closely withSpring Integration's Message Endpoint: any component that can be connected to MessageChannel(s) in order to send and/or receive Messages.

    Router

    A Message Router is responsible for deciding what channel or channels should receive the Messagenext (if any). Typically the decision is based upon the Message's content and/or metadata available inthe Message Headers. A Message Router is often used as a dynamic alternative to a statically configuredoutput 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 multiplesubscribers as described above.

  • Spring Integration

    2.2.4.RELEASESpring IntegrationReference Manual 11

    Splitter

    A Splitter is another type of Message Endpoint whose responsibility is to accept a Message from its inputchannel, split that Message into multiple Messages, and then send each of those to its output channel.This is typically used for dividing a "composite" payload object into a group of Messages containingthe sub-divided payloads.

    Aggregator

    Basically a mirror-image of the Splitter, the Aggregator is a type of Message Endpoint that receivesmultiple Messages and combines them into a single Message. In fact, Aggregators are often downstreamconsumers in a pipeline that includes a Splitter. Technically, the Aggregator is more complex than aSplitter, because it is required to maintain state (the Messages to-be-aggregated), to decide when thecomplete group of Messages is available, and to timeout if necessary. Furthermore, in case of a timeout,the Aggregator needs to know whether to send the partial results or to discard them to a separate channel.Spring Integration provides a CompletionStrategy as well as configurable settings for timeout,whether to send partial results upon timeout, and the discard channel.

    Service Activator

    A Service Activator is a generic endpoint for connecting a service instance to the messaging system.The input Message Channel must be configured, and if the service method to be invoked is capable ofreturning a value, an output Message Channel may also be provided.

    NoteThe output channel is optional, since each Message may also provide its own 'Return Address'header. This same rule applies for all consumer endpoints.

    The 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 aMessage-typed parameter). Whenever the service object's method returns a value, that return value willlikewise be converted to a reply Message if necessary (if it's not already a Message). That reply Messageis sent to the output channel. If no output channel has been configured, then the reply will be sent to thechannel specified in the Message's "return address" if available.

  • Spring Integration

    2.2.4.RELEASESpring IntegrationReference Manual 12

    A request-reply "Service Activator" endpoint connects atarget object's method to input and output Message Channels.

    Channel Adapter

    A 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 somemapping between the Message and whatever object or resource is received-from or sent-to the othersystem (File, HTTP Request, JMS Message, etc). Depending on the transport, the Channel Adaptermay also populate or extract Message header values. Spring Integration provides a number of ChannelAdapters, and they will be described in upcoming chapters.

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

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

  • Part III. Core MessagingThis section covers all aspects of the core messaging API in Spring Integration. Here you will learn aboutMessages, Message Channels, and Message Endpoints. Many of the Enterprise Integration Patternsare covered here as well, such as Filters, Routers, Transformers, Service-Activators, Splitters, andAggregators. The section also contains material about System Management, including the Control Busand Message History support.

  • Spring Integration

    2.2.4.RELEASESpring IntegrationReference Manual 14

    3. Messaging Channels3.1 Message ChannelsWhile the Message plays the crucial role of encapsulating data, it is the MessageChannel thatdecouples message producers from message consumers.

    The MessageChannel Interface

    Spring Integration's top-level MessageChannel interface is defined as follows.

    public interface MessageChannel {

    boolean send(Message message);

    boolean send(Message message, long timeout);}

    When sending a message, the return value will be true if the message is sent successfully. If the sendcall times out or is interrupted, then it will return false.

    PollableChannel

    Since Message Channels may or may not buffer Messages (as discussed in the overview), there aretwo sub-interfaces defining the buffering (pollable) and non-buffering (subscribable) channel behavior.Here is the definition of PollableChannel.

    public interface PollableChannel extends MessageChannel {

    Message receive();

    Message receive(long timeout);

    }

    Similar to the send methods, when receiving a message, the return value will be null in the case of atimeout or interrupt.

    SubscribableChannel

    The SubscribableChannel base interface is implemented by channels that send Messages directlyto their subscribed MessageHandlers. Therefore, they do not provide receive methods for polling,but instead define methods for managing those subscribers:

    public interface SubscribableChannel extends MessageChannel {

    boolean subscribe(MessageHandler handler);

    boolean unsubscribe(MessageHandler handler);

    }

  • Spring Integration

    2.2.4.RELEASESpring IntegrationReference Manual 15

    Message Channel Implementations

    Spring Integration provides several different Message Channel implementations. Each is brieflydescribed in the sections below.

    PublishSubscribeChannel

    The PublishSubscribeChannel implementation broadcasts any Message sent to it to all ofits subscribed handlers. This is most often used for sending Event Messages whose primary roleis notification as opposed to Document Messages which are generally intended to be processedby a single handler. Note that the PublishSubscribeChannel is intended for sending only.Since it broadcasts to its subscribers directly when its send(Message) method is invoked,consumers cannot poll for Messages (it does not implement PollableChannel and therefore has noreceive() method). Instead, any subscriber must be a MessageHandler itself, and the subscriber'shandleMessage(Message) method will be invoked in turn.

    QueueChannel

    The QueueChannel implementation wraps a queue. Unlike the PublishSubscribeChannel,the QueueChannel has point-to-point semantics. In other words, even if the channel has multipleconsumers, only one of them should receive any Message sent to that channel. It provides a defaultno-argument constructor (providing an essentially unbounded capacity of Integer.MAX_VALUE) aswell as a constructor that accepts the queue capacity:

    public QueueChannel(int capacity)

    A channel that has not reached its capacity limit will store messages in its internal queue, and thesend() method will return immediately even if no receiver is ready to handle the message. If thequeue has reached capacity, then the sender will block until room is available. Or, if using the sendcall that accepts a timeout, it will block until either room is available or the timeout period elapses,whichever occurs first. Likewise, a receive call will return immediately if a message is available on thequeue, but if the queue is empty, then a receive call may block until either a message is available orthe timeout elapses. In either case, it is possible to force an immediate return regardless of the queue'sstate by passing a timeout value of 0. Note however, that calls to the no-arg versions of send() andreceive() will block indefinitely.

    PriorityChannel

    Whereas the QueueChannel enforces first-in/first-out (FIFO) ordering, the PriorityChannel isan alternative implementation that allows for messages to be ordered within the channel based upon apriority. By default the priority is determined by the 'priority' header within each message. However,for custom priority determination logic, a comparator of type Comparator

  • Spring Integration

    2.2.4.RELEASESpring IntegrationReference Manual 16

    implementation of BlockingQueue). This works well in situations where the sender and receiverare operating in different threads but simply dropping the message in a queue asynchronously is notappropriate. In other words, with a RendezvousChannel at least the sender knows that some receiverhas accepted the message, whereas with a QueueChannel, the message would have been stored tothe internal queue and potentially never received.

    Tip

    Keep in mind that all of these queue-based channels are storing messages in-memory only bydefault. When persistence is required, you can either provide a 'message-store' attribute withinthe 'queue' element to reference a persistent MessageStore implementation, or you can replacethe local channel with one that is backed by a persistent broker, such as a JMS-backed channelor Channel Adapter. The latter option allows you to take advantage of any JMS provider'simplementation for message persistence, and it will be discussed in Chapter 19, JMS Support.However, when buffering in a queue is not necessary, the simplest approach is to rely uponthe DirectChannel discussed next.

    The RendezvousChannel is also useful for implementing request-reply operations. The sendercan create a temporary, anonymous instance of RendezvousChannel which it then sets as the'replyChannel' header when building a Message. After sending that Message, the sender can immediatelycall receive (optionally providing a timeout value) in order to block while waiting for a reply Message.This is very similar to the implementation used internally by many of Spring Integration's request-replycomponents.

    DirectChannel

    The DirectChannel has point-to-point semantics but otherwise is more similar to thePublishSubscribeChannel than any of the queue-based channel implementations describedabove. It implements the SubscribableChannel interface instead of the PollableChannelinterface, so it dispatches Messages directly to a subscriber. As a point-to-point channel, however, itdiffers from the PublishSubscribeChannel in that it will only send each Message to a singlesubscribed MessageHandler.

    In addition to being the simplest point-to-point channel option, one of its most important features isthat it enables a single thread to perform the operations on "both sides" of the channel. For example,if a handler is subscribed to a DirectChannel, then sending a Message to that channel will triggerinvocation of that handler's handleMessage(Message) method directly in the sender's thread,b


Recommended