spring integration reference manual · spring integration reference manual 5.0.0.release mark...
TRANSCRIPT
-
Spring Integration Reference Manual
5.0.0.RELEASE
Mark Fisher , Marius Bogoevici , Iwein Fuld , Jonas Partner , Oleg Zhurakousky , GaryRussell , Dave Syer , Josh Long , David Turanski , Gunnar Hillert , Artem Bilan , Amol Nayak
-
Copyright © 2009 2010 2011 2012 2013 2014 2015 2016 2017 Pivotal Software, Inc. All Rights Reserved.
Copies of this document may be made for your own use and for distribution to others, provided that you do not charge any feefor such copies and further provided that each copy contains this Copyright Notice, whether distributed in print or electronically.
-
Spring Integration Reference Manual
5.0.0.RELEASE Spring Integration iii
Table of Contents
I. Preface ................................................................................................................................... 1Requirements ..................................................................................................................... ii
1. Compatible Java Versions ....................................................................................... ii2. Compatible Versions of the Spring Framework ......................................................... ii3. Code Conventions .................................................................................................. ii
1. Conventions in this Book ................................................................................................ 3II. What’s new? .......................................................................................................................... 4
2. What’s new in Spring Integration 5.0? ............................................................................. 52.1. New Components ................................................................................................ 5
Java DSL ........................................................................................................... 5Testing Support .................................................................................................. 5MongoDB Outbound Gateway ............................................................................. 5WebFlux Gateways and Channel Adapters .......................................................... 5Content Type Conversion ................................................................................... 5ErrorMessagePublisher and ErrorMessageStrategy .............................................. 5JDBC Metadata Store ........................................................................................ 5
2.2. General Changes ................................................................................................ 6Core Changes .................................................................................................... 6Gateway Changes .............................................................................................. 7Aggregator Performance Changes ...................................................................... 7Splitter Changes ................................................................................................ 7JMS Changes .................................................................................................... 7Mail Changes ..................................................................................................... 7Feed Changes ................................................................................................... 8File Changes ..................................................................................................... 8(S)FTP Changes ................................................................................................ 8Integration Properties ......................................................................................... 9Stream Changes ................................................................................................ 9Barrier Changes ................................................................................................. 9AMQP Changes ................................................................................................. 9HTTP Changes ................................................................................................ 10MQTT Changes ................................................................................................ 10STOMP Changes ............................................................................................. 10Web Services Changes .................................................................................... 10Redis Changes ................................................................................................ 10TCP Changes .................................................................................................. 11Gemfire Changes ............................................................................................. 11Jdbc Changes .................................................................................................. 11
III. Overview of Spring Integration Framework ............................................................................ 123. Spring Integration Overview .......................................................................................... 13
3.1. Background ....................................................................................................... 133.2. Goals and Principles .......................................................................................... 133.3. Main Components ............................................................................................. 14
Message .......................................................................................................... 14Message Channel ............................................................................................ 14Message Endpoint ............................................................................................ 15
3.4. Message Endpoints ........................................................................................... 15
-
Spring Integration Reference Manual
5.0.0.RELEASE Spring Integration iv
Transformer ..................................................................................................... 16Filter ................................................................................................................ 16Router .............................................................................................................. 16Splitter ............................................................................................................. 16Aggregator ....................................................................................................... 17Service Activator .............................................................................................. 17Channel Adapter .............................................................................................. 18
3.5. Configuration and @EnableIntegration ................................................................ 183.6. Programming Considerations .............................................................................. 203.7. Programming Tips and Tricks ............................................................................. 20
XML Schemas .................................................................................................. 20Finding Class Names for Java and DSL Configuration ........................................ 21
3.8. POJO Method invocation ................................................................................... 23IV. Core Messaging .................................................................................................................. 25
4. Messaging Channels .................................................................................................... 264.1. Message Channels ............................................................................................ 26
The MessageChannel Interface ......................................................................... 26PollableChannel ....................................................................................... 26SubscribableChannel ................................................................................ 26
Message Channel Implementations ................................................................... 26PublishSubscribeChannel .......................................................................... 27QueueChannel ......................................................................................... 27PriorityChannel ......................................................................................... 27RendezvousChannel ................................................................................. 28DirectChannel .......................................................................................... 28ExecutorChannel ...................................................................................... 29Scoped Channel ....................................................................................... 30
Channel Interceptors ........................................................................................ 30MessagingTemplate .......................................................................................... 32Configuring Message Channels ......................................................................... 32
DirectChannel Configuration ...................................................................... 33Datatype Channel Configuration ................................................................ 33QueueChannel Configuration .................................................................... 34PublishSubscribeChannel Configuration ..................................................... 36ExecutorChannel ...................................................................................... 37PriorityChannel Configuration .................................................................... 37RendezvousChannel Configuration ............................................................ 38Scoped Channel Configuration .................................................................. 38Channel Interceptor Configuration ............................................................. 38Global Channel Interceptor Configuration ................................................... 38Wire Tap .................................................................................................. 39Conditional Wire Taps .............................................................................. 41Global Wire Tap Configuration .................................................................. 41
Special Channels ............................................................................................. 424.2. Poller ................................................................................................................ 42
Polling Consumer ............................................................................................. 42Pollable Message Source ................................................................................. 42Conditional Pollers for Message Sources ........................................................... 43
Background .............................................................................................. 43"Smart" Polling ......................................................................................... 43
-
Spring Integration Reference Manual
5.0.0.RELEASE Spring Integration v
SimpleActiveIdleMessageSourceAdvice ..................................................... 44CompoundTriggerAdvice ........................................................................... 44
4.3. Channel Adapter ............................................................................................... 45Configuring An Inbound Channel Adapter .......................................................... 45Configuring An Outbound Channel Adapter ........................................................ 46Channel Adapter Expressions and Scripts ......................................................... 47
4.4. Messaging Bridge .............................................................................................. 48Introduction ...................................................................................................... 48Configuring a Bridge with XML .......................................................................... 48Configuring a Bridge with Java Configuration ..................................................... 49Configuring a Bridge with the Java DSL ............................................................ 49
5. Message Construction .................................................................................................. 505.1. Message ........................................................................................................... 50
The Message Interface ..................................................................................... 50Message Headers ............................................................................................ 50
MessageHeaderAccessor API ................................................................... 51Message ID Generation ............................................................................ 52Read-only Headers ................................................................................... 53Header Propagation .................................................................................. 53
Message Implementations ................................................................................. 54The MessageBuilder Helper Class .................................................................... 54
6. Message Routing ......................................................................................................... 566.1. Routers ............................................................................................................. 56
Overview .......................................................................................................... 56Common Router Parameters ............................................................................. 58
Inside and Outside of a Chain ................................................................... 58Top-Level (Outside of a Chain) ................................................................. 59
Router Implementations .................................................................................... 60PayloadTypeRouter .................................................................................. 60HeaderValueRouter .................................................................................. 61RecipientListRouter ................................................................................... 62RecipientListRouterManagement ............................................................... 64XPath Router ........................................................................................... 64Routing and Error handling ....................................................................... 64
Configuring a Generic Router ............................................................................ 65Configuring a Content Based Router with XML ........................................... 65Configuring a Router with Annotations ....................................................... 67
Dynamic Routers .............................................................................................. 68Manage Router Mappings using the Control Bus ........................................ 71Manage Router Mappings using JMX ........................................................ 71Routing Slip ............................................................................................. 71Process Manager Enterprise Integration Pattern ......................................... 74
6.2. Filter ................................................................................................................. 74Introduction ...................................................................................................... 74Configuring Filter .............................................................................................. 75
Configuring a Filter with XML .................................................................... 75Configuring a Filter with Annotations ......................................................... 77
6.3. Splitter .............................................................................................................. 77Introduction ...................................................................................................... 77Programming model ......................................................................................... 77
-
Spring Integration Reference Manual
5.0.0.RELEASE Spring Integration vi
Configuring Splitter ........................................................................................... 79Configuring a Splitter using XML ............................................................... 79Configuring a Splitter with Annotations ....................................................... 80
6.4. Aggregator ........................................................................................................ 80Introduction ...................................................................................................... 80Functionality ..................................................................................................... 80Programming model ......................................................................................... 81
AggregatingMessageHandler ..................................................................... 81ReleaseStrategy ....................................................................................... 83Aggregating Large Groups ........................................................................ 85CorrelationStrategy ................................................................................... 85LockRegistry ............................................................................................ 86
Configuring an Aggregator ................................................................................ 86Configuring an Aggregator with XML ......................................................... 86Configuring an Aggregator with Annotations ............................................... 93
Managing State in an Aggregator: MessageGroupStore ...................................... 946.5. Resequencer ..................................................................................................... 96
Introduction ...................................................................................................... 96Functionality ..................................................................................................... 96Configuring a Resequencer ............................................................................... 96
6.6. Message Handler Chain ..................................................................................... 98Introduction ...................................................................................................... 98Configuring a Chain .......................................................................................... 99
6.7. Scatter-Gather ................................................................................................. 101Introduction .................................................................................................... 101Functionality ................................................................................................... 102Configuring a Scatter-Gather Endpoint ............................................................. 102
6.8. Thread Barrier ................................................................................................. 1047. Message Transformation ............................................................................................. 107
7.1. Transformer ..................................................................................................... 107Introduction .................................................................................................... 107Configuring Transformer ................................................................................. 107
Configuring Transformer with XML ........................................................... 107Common Transformers ........................................................................... 108Configuring a Transformer with Annotations ............................................. 113
Header Filter .................................................................................................. 114Codec-Based Transformers ............................................................................. 114
7.2. Content Enricher .............................................................................................. 114Introduction .................................................................................................... 114Header Enricher ............................................................................................. 114
Configuring a Header Enricher with Java Configuration ............................. 116Configuring a Header Enricher with the Java DSL .................................... 116Header Channel Registry ........................................................................ 116
Payload Enricher ............................................................................................ 117Configuration .......................................................................................... 118Examples ............................................................................................... 120
7.3. Claim Check .................................................................................................... 121Introduction .................................................................................................... 121Incoming Claim Check Transformer ................................................................. 121Outgoing Claim Check Transformer ................................................................. 122
-
Spring Integration Reference Manual
5.0.0.RELEASE Spring Integration vii
A word on Message Store .............................................................................. 1237.4. Codec ............................................................................................................. 124
Introduction .................................................................................................... 124EncodingPayloadTransformer .......................................................................... 124DecodingTransformer ...................................................................................... 124CodecMessageConverter ................................................................................ 124Kryo ............................................................................................................... 124
Customizing Kryo ................................................................................... 1248. Messaging Endpoints .................................................................................................. 127
8.1. Message Endpoints ......................................................................................... 127Message Handler ........................................................................................... 127Event Driven Consumer .................................................................................. 127Polling Consumer ........................................................................................... 128Endpoint Namespace Support ......................................................................... 129Change Polling Rate at Runtime ..................................................................... 133Payload Type Conversion ............................................................................... 134Content Type Conversion ............................................................................... 135Asynchronous polling ...................................................................................... 136Endpoint Inner Beans ..................................................................................... 137
8.2. Endpoint Roles ................................................................................................ 1378.3. Leadership Event Handling ............................................................................... 1398.4. Messaging Gateways ....................................................................................... 139
Enter the GatewayProxyFactoryBean ............................................................... 139Gateway XML Namespace Support ................................................................. 140Setting the Default Reply Channel ................................................................... 140Gateway Configuration with Annotations and/or XML ........................................ 141Mapping Method Arguments to a Message ...................................................... 142@MessagingGateway Annotation .................................................................... 143Invoking No-Argument Methods ....................................................................... 144Error Handling ................................................................................................ 145Gateway Timeouts .......................................................................................... 147Asynchronous Gateway .................................................................................. 148
Introduction ............................................................................................ 148ListenableFuture ..................................................................................... 148AsyncTaskExecutor ................................................................................ 149CompletableFuture ................................................................................. 150Reactor Mono ........................................................................................ 151
Gateway behavior when no response arrives ................................................... 1518.5. Service Activator .............................................................................................. 153
Introduction .................................................................................................... 153Configuring Service Activator .......................................................................... 153Asynchronous Service Activator ...................................................................... 156
8.6. Delayer ........................................................................................................... 156Introduction .................................................................................................... 156Configuring a Delayer ..................................................................................... 156Delayer and a Message Store ......................................................................... 159
8.7. Scripting support .............................................................................................. 160Script configuration ......................................................................................... 160
8.8. Groovy support ................................................................................................ 162Groovy configuration ....................................................................................... 163
-
Spring Integration Reference Manual
5.0.0.RELEASE Spring Integration viii
Control Bus .................................................................................................... 1648.9. Adding Behavior to Endpoints .......................................................................... 165
Introduction .................................................................................................... 165Provided Advice Classes ................................................................................ 166
Retry Advice .......................................................................................... 166Circuit Breaker Advice ............................................................................ 172Expression Evaluating Advice .................................................................. 173
Custom Advice Classes .................................................................................. 174Other Advice Chain Elements ......................................................................... 175Handle Message Advice ................................................................................. 176Transaction Support ....................................................................................... 176Advising Filters ............................................................................................... 178Advising Endpoints Using Annotations ............................................................. 178Ordering Advices within an Advice Chain ......................................................... 178Advised Handler Properties ............................................................................. 178Idempotent Receiver Enterprise Integration Pattern .......................................... 179
8.10. Logging Channel Adapter ............................................................................... 181Configuring with Java Configuration ................................................................. 181Configuring with the Java DSL ........................................................................ 182
9. Java DSL ................................................................................................................... 1839.1. Example Configurations ................................................................................... 1839.2. Introduction ..................................................................................................... 1839.3. DSL Basics ..................................................................................................... 1849.4. Message Channels .......................................................................................... 1859.5. Pollers ............................................................................................................. 1869.6. DSL and Endpoint Configuration ....................................................................... 1869.7. Transformers ................................................................................................... 1879.8. Inbound Channel Adapters ............................................................................... 1879.9. Message Routers ............................................................................................. 1889.10. Splitters ......................................................................................................... 1899.11. Aggregators and Resequencers ...................................................................... 1899.12. ServiceActivators (.handle()) ........................................................................... 1909.13. Operator log() ................................................................................................ 1919.14. MessageChannelSpec.wireTap() ..................................................................... 1919.15. Working With Message Flows ......................................................................... 1919.16. FunctionExpression ........................................................................................ 1929.17. Sub Flows support ......................................................................................... 1929.18. Using Protocol Adapters ................................................................................. 1939.19. IntegrationFlowAdapter ................................................................................... 1959.20. Dynamic and runtime Integration Flows ........................................................... 1969.21. IntegrationFlow as Gateway ........................................................................... 198
10. System Management ................................................................................................ 19910.1. Metrics and Management ............................................................................... 199
Configuring Metrics Capture ............................................................................ 199MessageChannel Metric Features ................................................................... 200MessageHandler Metric Features .................................................................... 201Time-Based Average Estimates ....................................................................... 201Metrics Factory ............................................................................................... 202
10.2. JMX Support ................................................................................................. 203Notification Listening Channel Adapter ............................................................. 203
-
Spring Integration Reference Manual
5.0.0.RELEASE Spring Integration ix
Notification Publishing Channel Adapter ........................................................... 204Attribute Polling Channel Adapter .................................................................... 205Tree Polling Channel Adapter ......................................................................... 205Operation Invoking Channel Adapter ............................................................... 205Operation Invoking Outbound Gateway ............................................................ 206MBean Exporter ............................................................................................. 206
MBean ObjectNames .............................................................................. 207JMX Improvements ................................................................................. 208Orderly Shutdown Managed Operation .................................................... 210
10.3. Message History ............................................................................................ 210Message History Configuration ........................................................................ 211
10.4. Message Store .............................................................................................. 212MessageGroupFactory .................................................................................... 214Persistence MessageGroupStore and Lazy-Load .............................................. 214
10.5. Metadata Store .............................................................................................. 215Idempotent Receiver and Metadata Store ........................................................ 216MetadataStoreListener .................................................................................... 216
10.6. Control Bus ................................................................................................... 21610.7. Orderly Shutdown .......................................................................................... 21710.8. Integration Graph ........................................................................................... 218
Graph Runtime Model ..................................................................................... 22110.9. Integration Graph Controller ........................................................................... 222
V. Integration Endpoints .......................................................................................................... 22411. Endpoint Quick Reference Table ............................................................................... 22512. AMQP Support ......................................................................................................... 229
12.1. Introduction .................................................................................................... 22912.2. Inbound Channel Adapter ............................................................................... 229
Configuring with Java Configuration ................................................................. 232Configuring with the Java DSL ........................................................................ 233
12.3. Inbound Gateway ........................................................................................... 234Configuring with Java Configuration ................................................................. 235Configuring with the Java DSL ........................................................................ 236
12.4. Inbound Endpoint Acknowledge Mode ............................................................. 23612.5. Outbound Channel Adapter ............................................................................ 237
Configuring with Java Configuration ................................................................. 239Configuring with the Java DSL ........................................................................ 239
12.6. Outbound Gateway ........................................................................................ 240Configuring with Java Configuration ................................................................. 242Configuring with the Java DSL ........................................................................ 243
12.7. Async Outbound Gateway .............................................................................. 244Configuring with Java Configuration ................................................................. 246Configuring with the Java DSL ........................................................................ 246
12.8. Outbound Message Conversion ...................................................................... 24712.9. Outbound User Id .......................................................................................... 24812.10. Delayed Message Exchange ......................................................................... 24812.11. AMQP Backed Message Channels ................................................................ 249
Configuring with Java Configuration ................................................................. 250Configuring with the Java DSL ........................................................................ 250
12.12. AMQP Message Headers ............................................................................. 25112.13. AMQP Samples ........................................................................................... 253
-
Spring Integration Reference Manual
5.0.0.RELEASE Spring Integration x
13. Spring ApplicationEvent Support ................................................................................ 25513.1. Receiving Spring Application Events ............................................................... 25513.2. Sending Spring Application Events .................................................................. 255
14. Feed Adapter ........................................................................................................... 25714.1. Introduction .................................................................................................... 25714.2. Feed Inbound Channel Adapter ...................................................................... 25714.3. Java DSL and Annotation configuration ........................................................... 258
15. File Support ............................................................................................................. 25915.1. Introduction .................................................................................................... 25915.2. Reading Files ................................................................................................ 259
Namespace Support ....................................................................................... 262WatchServiceDirectoryScanner ........................................................................ 264Limiting Memory Consumption ........................................................................ 265Configuring with Java Configuration ................................................................. 265Configuring with the Java DSL ........................................................................ 265'Tail’ing Files .................................................................................................. 266Dealing With Incomplete Data ......................................................................... 268
15.3. Writing files ................................................................................................... 268Generating File Names ................................................................................... 268Specifying the Output Directory ....................................................................... 269Dealing with Existing Destination Files ............................................................. 270Flushing Files When using APPEND_NO_FLUSH ............................................ 271File Timestamps ............................................................................................. 272File Permissions ............................................................................................. 272File Outbound Channel Adapter ...................................................................... 272Outbound Gateway ......................................................................................... 272Configuring with Java Configuration ................................................................. 273Configuring with the Java DSL ........................................................................ 274
15.4. File Transformers ........................................................................................... 27415.5. File Splitter .................................................................................................... 275
Configuring with Java Configuration ................................................................. 276Configuring with the Java DSL ........................................................................ 276
16. FTP/FTPS Adapters .................................................................................................. 27816.1. Introduction .................................................................................................... 27816.2. FTP Session Factory ..................................................................................... 278
Default Factories ............................................................................................ 278FTPS and Shared SSLSession ....................................................................... 280
16.3. Delegating Session Factory ............................................................................ 28116.4. FTP Inbound Channel Adapter ....................................................................... 282
Recovering from Failures ................................................................................ 285Configuring with Java Configuration ................................................................. 286Configuring with the Java DSL ........................................................................ 287Dealing With Incomplete Data ......................................................................... 288
16.5. FTP Streaming Inbound Channel Adapter ....................................................... 288Configuring with Java Configuration ................................................................. 289
16.6. Inbound Channel Adapters: Controlling Remote File Fetching ........................... 29016.7. FTP Outbound Channel Adapter ..................................................................... 291
Configuring with Java Configuration ................................................................. 292Configuring with the Java DSL ........................................................................ 293
16.8. FTP Outbound Gateway ................................................................................. 294
-
Spring Integration Reference Manual
5.0.0.RELEASE Spring Integration xi
Configuring with Java Configuration ................................................................. 299Configuring with the Java DSL ........................................................................ 300Outbound Gateway Partial Success (mget and mput) ....................................... 300
16.9. FTP Session Caching .................................................................................... 30116.10. RemoteFileTemplate .................................................................................... 30216.11. MessageSessionCallback ............................................................................. 302
17. GemFire Support ...................................................................................................... 30417.1. Introduction .................................................................................................... 30417.2. Inbound Channel Adapter ............................................................................... 30417.3. Continuous Query Inbound Channel Adapter ................................................... 30417.4. Outbound Channel Adapter ............................................................................ 30517.5. Gemfire Message Store ................................................................................. 30617.6. Gemfire Lock Registry .................................................................................... 30717.7. Gemfire Metadata Store ................................................................................. 307
18. HTTP Support .......................................................................................................... 30918.1. Introduction .................................................................................................... 30918.2. Http Inbound Components .............................................................................. 30918.3. Http Outbound Components ........................................................................... 311
HttpRequestExecutingMessageHandler ............................................................ 31118.4. HTTP Namespace Support ............................................................................. 312
Introduction .................................................................................................... 312Inbound .......................................................................................................... 312Request Mapping Support ............................................................................... 313Cross-Origin Resource Sharing (CORS) Support .............................................. 314Response StatusCode .................................................................................... 315URI Template Variables and Expressions ........................................................ 316Outbound ....................................................................................................... 316Mapping URI Variables ................................................................................... 318Controlling URI Encoding ................................................................................ 319
18.5. Configuring HTTP Endpoints with Java ........................................................... 32018.6. Timeout Handling ........................................................................................... 32118.7. HTTP Proxy configuration ............................................................................... 32318.8. HTTP Header Mappings ................................................................................. 32418.9. Integration Graph Controller ........................................................................... 32518.10. HTTP Samples ............................................................................................ 325
Multipart HTTP request - RestTemplate (client) and Http Inbound Gateway(server) .......................................................................................................... 325
19. JDBC Support .......................................................................................................... 32719.1. Inbound Channel Adapter ............................................................................... 327
Polling and Transactions ................................................................................. 329Max-rows-per-poll versus Max-messages-per-poll ............................................. 329
19.2. Outbound Channel Adapter ............................................................................ 33019.3. Outbound Gateway ........................................................................................ 33119.4. JDBC Message Store ..................................................................................... 332
Initializing the Database .................................................................................. 333The Generic JDBC Message Store .................................................................. 333Backing Message Channels ............................................................................ 333Partitioning a Message Store .......................................................................... 336
19.5. Stored Procedures ......................................................................................... 336Supported Databases ..................................................................................... 336
-
Spring Integration Reference Manual
5.0.0.RELEASE Spring Integration xii
Configuration .................................................................................................. 337Common Configuration Attributes .................................................................... 337Common Configuration Sub-Elements ............................................................. 339Defining Parameter Sources ........................................................................... 340Stored Procedure Inbound Channel Adapter .................................................... 341Stored Procedure Outbound Channel Adapter .................................................. 342Stored Procedure Outbound Gateway .............................................................. 342Examples ....................................................................................................... 343
19.6. JDBC Lock Registry ....................................................................................... 34419.7. JDBC Metadata Store .................................................................................... 344
20. JPA Support ............................................................................................................. 34620.1. Supported Persistence Providers .................................................................... 34620.2. Java Implementation ...................................................................................... 34720.3. Namespace Support ....................................................................................... 347
Common XML Namespace Configuration Attributes .......................................... 347Providing JPA Query Parameters .................................................................... 349Transaction Handling ...................................................................................... 349
20.4. Inbound Channel Adapter ............................................................................... 350Configuration Parameter Reference ................................................................. 351Configuring with Java Configuration ................................................................. 352Configuring with the Java DSL ........................................................................ 352
20.5. Outbound Channel Adapter ............................................................................ 353Using an Entity Class ..................................................................................... 353Using JPA Query Language (JPA QL) ............................................................. 354Using Native Queries ...................................................................................... 355Using Named Queries .................................................................................... 355Configuration Parameter Reference ................................................................. 356Configuring with Java Configuration ................................................................. 357Configuring with the Java DSL ........................................................................ 358
20.6. Outbound Gateways ....................................................................................... 359Common Configuration Parameters ................................................................. 360Updating Outbound Gateway .......................................................................... 361Configuring with Java Configuration ................................................................. 361Configuring with the Java DSL ........................................................................ 362Retrieving Outbound Gateway ......................................................................... 363Configuring with Java Configuration ................................................................. 363Configuring with the Java DSL ........................................................................ 364JPA Outbound Gateway Samples .................................................................... 365
21. JMS Support ............................................................................................................ 36721.1. Inbound Channel Adapter ............................................................................... 367
Transactions ................................................................................................... 36821.2. Message-Driven Channel Adapter ................................................................... 368
Inbound Conversion Errors ............................................................................. 36921.3. Outbound Channel Adapter ............................................................................ 370
Transactions ................................................................................................... 37021.4. Inbound Gateway ........................................................................................... 37021.5. Outbound Gateway ........................................................................................ 372
Gateway Reply Correlation ............................................................................. 373Async Gateway .............................................................................................. 375Attribute Reference ......................................................................................... 376
-
Spring Integration Reference Manual
5.0.0.RELEASE Spring Integration xiii
21.6. Mapping Message Headers to/from JMS Message ........................................... 37821.7. Message Conversion, Marshalling and Unmarshalling ...................................... 37821.8. JMS Backed Message Channels ..................................................................... 37921.9. Using JMS Message Selectors ....................................................................... 38021.10. JMS Samples .............................................................................................. 381
22. Mail Support ............................................................................................................. 38222.1. Mail-Sending Channel Adapter ....................................................................... 38222.2. Mail-Receiving Channel Adapter ..................................................................... 38222.3. Inbound Mail Message Mapping ..................................................................... 38322.4. Mail Namespace Support ............................................................................... 38422.5. Marking IMAP Messages When \Recent is Not Supported ................................ 38822.6. Email Message Filtering ................................................................................. 38822.7. Transaction Synchronization ........................................................................... 389
23. MongoDb Support ..................................................................................................... 39123.1. Introduction .................................................................................................... 39123.2. Connecting to MongoDb ................................................................................. 39123.3. MongoDB Message Store ............................................................................... 392
MongoDB Channel Message Store .................................................................. 392MongoDB Metadata Store ............................................................................... 393
23.4. MongoDB Inbound Channel Adapter ............................................................... 39423.5. MongoDB Outbound Channel Adapter ............................................................. 39623.6. MongoDB Outbound Gateway ........................................................................ 396
Configuring with Java Configuration ................................................................. 397Configuring with the Java DSL ........................................................................ 397
24. MQTT Support ......................................................................................................... 39924.1. Introduction .................................................................................................... 39924.2. Inbound (message-driven) Channel Adapter .................................................... 399
Adding/Removing Topics at Runtime ............................................................... 400Configuring with Java Configuration ................................................................. 401
24.3. Outbound Channel Adapter ............................................................................ 401Configuring with Java Configuration ................................................................. 402
25. Redis Support .......................................................................................................... 40425.1. Introduction .................................................................................................... 40425.2. Connecting to Redis ....................................................................................... 40425.3. Messaging with Redis .................................................................................... 405
Redis Publish/Subscribe channel ..................................................................... 405Redis Inbound Channel Adapter ...................................................................... 405Redis Outbound Channel Adapter ................................................................... 406Redis Queue Inbound Channel Adapter ........................................................... 407Redis Queue Outbound Channel Adapter ........................................................ 408Redis Application Events ................................................................................ 408
25.4. Redis Message Store ..................................................................................... 409Redis Channel Message Stores ...................................................................... 409
25.5. Redis Metadata Store .................................................................................... 41025.6. RedisStore Inbound Channel Adapter ............................................................. 41125.7. RedisStore Outbound Channel Adapter ........................................................... 41325.8. Redis Outbound Command Gateway .............................................................. 41425.9. Redis Queue Outbound Gateway .................................................................... 41525.10. Redis Queue Inbound Gateway .................................................................... 41525.11. Redis Lock Registry ..................................................................................... 416
-
Spring Integration Reference Manual
5.0.0.RELEASE Spring Integration xiv
26. Resource Support ..................................................................................................... 41826.1. Introduction .................................................................................................... 41826.2. Resource Inbound Channel Adapter ................................................................ 418
27. RMI Support ............................................................................................................. 42027.1. Introduction .................................................................................................... 42027.2. Outbound RMI ............................................................................................... 42027.3. Inbound RMI .................................................................................................. 42027.4. RMI namespace support ................................................................................ 42027.5. Configuring with Java Configuration ................................................................ 421
28. SFTP Adapters ......................................................................................................... 42228.1. Introduction .................................................................................................... 42228.2. SFTP Session Factory ................................................................................... 422
Configuration Properties .................................................................................. 42328.3. Proxy Factory Bean ....................................................................................... 42528.4. Delegating Session Factory ............................................................................ 42528.5. SFTP Session Caching .................................................................................. 42628.6. RemoteFileTemplate ...................................................................................... 42628.7. SFTP Inbound Channel Adapter ..................................................................... 427
Recovering from Failures ................................................................................ 429Configuring with Java Configuration ................................................................. 430Configuring with the Java DSL ........................................................................ 431Dealing With Incomplete Data ......................................................................... 432
28.8. SFTP Streaming Inbound Channel Adapter ..................................................... 432Configuring with Java Configuration ................................................................. 433
28.9. Inbound Channel Adapters: Controlling Remote File Fetching ........................... 43428.10. SFTP Outbound Channel Adapter ................................................................. 435
Configuring with Java Configuration ................................................................. 436Configuring with the Java DSL ........................................................................ 437
28.11. SFTP Outbound Gateway ............................................................................. 438Configuring with Java Configuration ................................................................. 443Configuring with the Java DSL ........................................................................ 443Outbound Gateway Partial Success (mget and mput) ....................................... 444
28.12. SFTP/JSCH Logging .................................................................................... 44528.13. MessageSessionCallback ............................................................................. 445
29. STOMP Support ....................................................................................................... 44629.1. Introduction .................................................................................................... 44629.2. Overview ....................................................................................................... 44629.3. STOMP Inbound Channel Adapter .................................................................. 44629.4. STOMP Outbound Channel Adapter ............................................................... 44629.5. STOMP Headers Mapping .............................................................................. 44729.6. STOMP Integration Events ............................................................................. 44729.7. STOMP Adapters Java Configuration .............................................................. 44829.8. STOMP Namespace Support .......................................................................... 449
30. Stream Support ........................................................................................................ 45130.1. Introduction .................................................................................................... 45130.2. Reading from streams .................................................................................... 45130.3. Writing to streams .......................................................................................... 45230.4. Stream namespace support ............................................................................ 452
31. Syslog Support ......................................................................................................... 45431.1. Introduction .................................................................................................... 454
-
Spring Integration Reference Manual
5.0.0.RELEASE Spring Integration xv
31.2. Syslog ................................................................. 454Example Configuration .................................................................................... 454
32. TCP and UDP Support ............................................................................................. 45732.1. Introduction .................................................................................................... 45732.2. UDP Adapters ............................................................................................... 457
Outbound (XML Configuration) ........................................................................ 457Outbound (Java Configuration) ........................................................................ 459Outbound (Java DSL Configuration) ................................................................ 459Inbound (XML Configuration) ........................................................................... 459Inbound (Java Configuration) .......................................................................... 459Inbound (Java DSL Configuration) ................................................................... 459Advanced Outbound Configuration .................................................................. 460
32.3. TCP Connection Factories .............................................................................. 460TCP Caching Client Connection Factory .......................................................... 464TCP Failover Client Connection Factory .......................................................... 464TCP Thread Affinity Connection Factory .......................................................... 465
32.4. TCP Connection Interceptors .......................................................................... 46532.5. TCP Connection Events ................................................................................. 46632.6. TCP Adapters ................................................................................................ 46732.7. TCP Gateways .............................................................................................. 46932.8. TCP Message Correlation .............................................................................. 470
Overview ........................................................................................................ 470Gateways ....................................................................................................... 470Collaborating Outbound and Inbound Channel Adapters ................................... 470Transferring Headers ...................................................................................... 471
32.9. A Note About NIO .......................................................................................... 473Thread Pool Task Executor with CALLER_RUNS Policy ................................... 473
32.10. SSL/TLS Support ......................................................................................... 475Overview ........................................................................................................ 475Getting Started ............................................................................................... 475
32.11. Advanced Techniques .................................................................................. 476Strategy Interfaces ......................................................................................... 476Example: Enabling SSL Client Authentication ................................................... 478
32.12. IP Configuration Attributes ............................................................................ 47932.13. IP Message Headers .................................................................................... 48632.14. Annotation-Based Configuration .................................................................... 487
33. Twitter Support ......................................................................................................... 49033.1. Introduction .................................................................................................... 49033.2. Twitter OAuth Configuration ............................................................................ 49033.3. Twitter Template ............................................................................................ 49033.4. Twitter Inbound Adapters ............................................................................... 491
Inbound Message Channel Adapter ................................................................. 492Direct Inbound Message Channel Adapter ....................................................... 492Mentions Inbound Message Channel Adapter .................................................. 492Search Inbound Message Channel Adapter ..................................................... 492
33.5. Twitter Outbound Adapter ............................................................................... 493Twitter Outbound Update Channel Adapter ...................................................... 493Twitter Outbound Direct Message Channel Adapter .......................................... 494
33.6. Twitter Search Outbound Gateway .................................................................. 49434. WebFlux Support ...................................................................................................... 496
-
Spring Integration Reference Manual
5.0.0.RELEASE Spring Integration xvi
34.1. Introduction .................................................................................................... 49634.2. WebFlux Inbound Components ....................................................................... 49634.3. WebFlux Outbound Components .................................................................... 49734.4. WebFlux Namespace Support ........................................................................ 497
Introduction .................................................................................................... 497Inbound .......................................................................................................... 498Outbound ....................................................................................................... 498
34.5. Configuring WebFlux Endpoints with Java ....................................................... 49834.6. WebFlux Header Mappings ............................................................................ 499
35. WebSockets Support ................................................................................................ 50035.1. Introduction .................................................................................................... 50035.2. Overview ....................................................................................................... 50035.3. WebSocket Inbound Channel Adapter ............................................................. 50135.4. WebSocket Outbound Channel Adapter .......................................................... 50235.5. WebSockets Namespace Support ................................................................... 50335.6. ClientStompEncoder ....................................................................................... 506
36. Web Services Support .............................................................................................. 50836.1. Outbound Web Service Gateways ................................................................... 50836.2. Inbound Web Service Gateways ..................................................................... 50836.3. Web Service Namespace Support ................................................................... 50936.4. Outbound URI Configuration ........................................................................... 51036.5. WS Message Headers ................................................................................... 51136.6. MTOM Support .............................................................................................. 512
37. XML Support - Dealing with XML Payloads ................................................................ 51437.1. Introduction .................................................................................................... 51437.2. Namespace Support ....................................................................................... 514
XPath Expressions ......................................................................................... 515Providing Namespaces (Optional) to XPath Expressions ........................... 515Using XPath Expressions with Default Namespaces ................................. 516
37.3. Transforming XML Payloads ........................................................................... 517Configuring Transformers as Beans ................................................................. 517
UnmarshallingTransformer ...................................................................... 518MarshallingTransformer ........................................................................... 518XsltPayloadTransformer .......................................................................... 519ResultTransformers ................................................................................. 519
Namespace Support for XML Transformers ...................................................... 520Namespace Configuration and ResultTransformers ........................................... 521
37.4. Transforming XML Messages Using XPath ...................................................... 52337.5. Splitting XML Messages ................................................................................. 52437.6. Routing XML Messages Using XPath .............................................................. 525
XML Payload Converter .................................................................................. 52737.7. XPath Header Enricher .................................................................................. 52737.8. Using the XPath Filter .................................................................................... 52837.9. #xpath SpEL Function .................................................................................... 52937.10. XML Validating Filter .................................................................................... 530
38. XMPP Support ......................................................................................................... 53138.1. Introduction .................................................................................................... 53138.2. XMPP Connection .......................................................................................... 53138.3. XMPP Messages ........................................................................................... 532
Inbound Message Channel Adapter ................................................................. 532
-
Spring Integration Reference Manual
5.0.0.RELEASE Spring Integration xvii
Outbound Message Channel Adapter .............................................................. 53338.4. XMPP Presence ............................................................................................ 533
Inbound Presence Message Channel Adapter .................................................. 533Outbound Presence Message Channel Adapter ............................................... 534
38.5. Advanced Configuration ................................................................................. 53438.6. XMPP Message Headers ............................................................................... 53538.7. XMPP Extensions .......................................................................................... 536
39. Zookeeper Support ................................................................................................... 53839.1. Introduction .................................................................................................... 53839.2. Zookeeper Metadata Store ............................................................................. 53839.3. Zookeeper Lock Registry ................................................................................ 53839.4. Zookeeper Leadership Event Handling ............................................................ 538
VI. Appendices ....................................................................................................................... 540A. Spring Expression Language (SpEL) ........................................................................... 541
A.1. Introduction ..................................................................................................... 541A.2. SpEL Evaluation Context Customization ........................................................... 541A.3. SpEL Functions ............................................................................................... 542A.4. PropertyAccessors ........................................................................................... 543
B. Message Publishing ................................................................................................... 545B.1. Message Publishing Configuration .................................................................... 545
Annotation-driven approach via @Publisher annotation ..................................... 545XML-based approach via the element .......................... 547Producing and publishing messages based on a scheduled trigger .................... 549
C. Transaction Support ................................................................................................... 551C.1. Understanding Transactions in Message flows .................................................. 551
Poller Transaction Support .............................................................................. 552C.2. Transaction Boundaries ................................................................................... 553C.3. Transaction Synchronization ............................................................................ 553C.4. Pseudo Transactions ....................................................................................... 555
D. Security in Spring Integration ...................................................................................... 557D.1. Introduction ..................................................................................................... 557D.2. Securing channels ........................................................................................... 557D.3. SecurityContext Propagation ............................................................................ 558
E. Configuration ............................................................................................................. 561E.1. Introduction ..................................................................................................... 561E.2. Namespace Support ........................................................................................ 561E.3. Configuring the Task Scheduler ....................................................................... 562E.4. Error Handling ................................................................................................. 563E.5. Global Properties ............................................................................................. 564E.6. Annotation Support .......................................................................................... 565
Messaging Meta-Annotations .......................................................................... 570Annotations on @Beans ................................................................................. 570Creating a Bridge with Annotations .................................................................. 572Advising Annotated Endpoints ......................................................................... 573
E.7. Message Mapping rules and conventions .......................................................... 573Simple Scenarios ............................................................................................ 573Complex Scenarios ......................................................................................... 575
F. Testing support .......................................................................................................... 577F.1. Introduction ..................................................................................................... 577F.2. Testing Utilities ................................................................................................ 578
-
Spring Integration Reference Manual
5.0.0.RELEASE Spring Integration xviii
TestUtils ......................................................................................................... 578SocketUtils ..................................................................................................... 578OnlyOnceTrigger ............................................................................................ 579Support Components ...................................................................................... 579Hamcrest and Mockito Matchers ..................................................................... 579
F.3. Spring Integration and test context ................................................................... 580F.4. Integration Mocks ............................................................................................ 581
MockIntegration .............................................................................................. 581F.5. Other Resources ............................................................................................. 582
G. Spring Integration Samples ........................................................................................ 583G.1. Introduction ..................................................................................................... 583G.2. Where to get Samples .................................................................................... 583G.3. Submitting Samples or Sample Requests ......................................................... 583G.4. Samples Structure ........................................................................................... 584G.5. Samples ......................................................................................................... 585
Loan Broker ................................................................................................... 586The Cafe Sample ........................................................................................... 590The XML Messaging Sample .......................................................................... 594
H. Additional Resources ................................................................................................. 595H.1. Spring Integration Home .................................................................................. 595
I. Change History ........................................................................................................... 596I.1. Changes between 4.2 and 4.3 ........................................................................... 596I.2. New Components ............................................................................................. 596
AMQP Async Outbound Gateway .................................................................... 596MessageGroupFactory .................................................................................... 596PersistentMessageGroup ................................................................................ 596FTP/SFTP Streaming Inbound Channel Adapters ............................................. 596Stream Transformer ........................................................................................ 596Integration Graph ................................