spring integration reference manual - spring … · spring integration reference manual...
TRANSCRIPT
-
Spring Integration Reference Manual
5.0.7.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 2018 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.7.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. Whats new? .......................................................................................................................... 4
2. Whats 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 .................................................................................................. 11Metrics Changes .............................................................................................. 11@EndpointId Annotations .................................................................................. 11Integration Flows: Generated bean names ......................................................... 12
III. Overview of Spring Integration Framework ............................................................................ 133. Spring Integration Overview .......................................................................................... 14
3.1. Background ....................................................................................................... 143.2. Goals and Principles .......................................................................................... 143.3. Main Components ............................................................................................. 15
Message .......................................................................................................... 15
-
Spring Integration Reference Manual
5.0.7.RELEASE Spring Integration iv
Message Channel ............................................................................................ 15Message Endpoint ............................................................................................ 16
3.4. Message Endpoints ........................................................................................... 16Transformer ..................................................................................................... 17Filter ................................................................................................................ 17Router .............................................................................................................. 17Splitter ............................................................................................................. 17Aggregator ....................................................................................................... 18Service Activator .............................................................................................. 18Channel Adapter .............................................................................................. 19Endpoint Bean Names ...................................................................................... 19
3.5. Configuration and @EnableIntegration ................................................................ 223.6. Programming Considerations .............................................................................. 233.7. Considerations When using Packaged (e.g. Shaded) Jars .................................... 233.8. Programming Tips and Tricks ............................................................................. 25
XML Schemas .................................................................................................. 25Finding Class Names for Java and DSL Configuration ........................................ 26
3.9. POJO Method invocation ................................................................................... 28IV. Core Messaging .................................................................................................................. 30
4. Messaging Channels .................................................................................................... 314.1. Message Channels ............................................................................................ 31
The MessageChannel Interface ......................................................................... 31PollableChannel ....................................................................................... 31SubscribableChannel ................................................................................ 31
Message Channel Implementations ................................................................... 31PublishSubscribeChannel .......................................................................... 32QueueChannel ......................................................................................... 32PriorityChannel ......................................................................................... 32RendezvousChannel ................................................................................. 33DirectChannel .......................................................................................... 33ExecutorChannel ...................................................................................... 34Scoped Channel ....................................................................................... 35
Channel Interceptors ........................................................................................ 35MessagingTemplate .......................................................................................... 37Configuring Message Channels ......................................................................... 37
DirectChannel Configuration ...................................................................... 38Datatype Channel Configuration ................................................................ 38QueueChannel Configuration .................................................................... 39PublishSubscribeChannel Configuration ..................................................... 41ExecutorChannel ...................................................................................... 42PriorityChannel Configuration .................................................................... 42RendezvousChannel Configuration ............................................................ 43Scoped Channel Configuration .................................................................. 43Channel Interceptor Configuration ............................................................. 43Global Channel Interceptor Configuration ................................................... 43Wire Tap .................................................................................................. 45Conditional Wire Taps .............................................................................. 46Global Wire Tap Configuration .................................................................. 47
Special Channels ............................................................................................. 474.2. Poller ................................................................................................................ 47
-
Spring Integration Reference Manual
5.0.7.RELEASE Spring Integration v
Polling Consumer ............................................................................................. 47Pollable Message Source ................................................................................. 48Deferred Acknowledgment Pollable Message Source ......................................... 48Conditional Pollers for Message Sources ........................................................... 50
Background .............................................................................................. 50"Smart" Polling ......................................................................................... 50SimpleActiveIdleMessageSourceAdvice ..................................................... 51CompoundTriggerAdvice ........................................................................... 51
4.3. Channel Adapter ............................................................................................... 52Configuring An Inbound Channel Adapter .......................................................... 52Configuring An Outbound Channel Adapter ........................................................ 53Channel Adapter Expressions and Scripts ......................................................... 54
4.4. Messaging Bridge .............................................................................................. 54Introduction ...................................................................................................... 54Configuring a Bridge with XML .......................................................................... 55Configuring a Bridge with Java Configuration ..................................................... 55Configuring a Bridge with the Java DSL ............................................................ 56
5. Message Construction .................................................................................................. 575.1. Message ........................................................................................................... 57
The Message Interface ..................................................................................... 57Message Headers ............................................................................................ 57
MessageHeaderAccessor API ................................................................... 58Message ID Generation ............................................................................ 60Read-only Headers ................................................................................... 60Header Propagation .................................................................................. 61
Message Implementations ................................................................................. 61The MessageBuilder Helper Class .................................................................... 62
6. Message Routing ......................................................................................................... 646.1. Routers ............................................................................................................. 64
Overview .......................................................................................................... 64Common Router Parameters ............................................................................. 66
Inside and Outside of a Chain ................................................................... 66Top-Level (Outside of a Chain) ................................................................. 67
Router Implementations .................................................................................... 68PayloadTypeRouter .................................................................................. 68HeaderValueRouter .................................................................................. 69RecipientListRouter ................................................................................... 70RecipientListRouterManagement ............................................................... 72XPath Router ........................................................................................... 72Routing and Error handling ....................................................................... 72
Configuring a Generic Router ............................................................................ 73Configuring a Content Based Router with XML ........................................... 73Configuring a Router with Annotations ....................................................... 75
Dynamic Routers .............................................................................................. 76Manage Router Mappings using the Control Bus ........................................ 79Manage Router Mappings using JMX ........................................................ 79Routing Slip ............................................................................................. 79Process Manager Enterprise Integration Pattern ......................................... 82
6.2. Filter ................................................................................................................. 82Introduction ...................................................................................................... 82
-
Spring Integration Reference Manual
5.0.7.RELEASE Spring Integration vi
Configuring Filter .............................................................................................. 83Configuring a Filter with XML .................................................................... 83Configuring a Filter with Annotations ......................................................... 85
6.3. Splitter .............................................................................................................. 85Introduction ...................................................................................................... 85Programming model ......................................................................................... 85Configuring Splitter ........................................................................................... 87
Configuring a Splitter using XML ............................................................... 87Configuring a Splitter with Annotations ....................................................... 88
6.4. Aggregator ........................................................................................................ 88Introduction ...................................................................................................... 88Functionality ..................................................................................................... 88Programming model ......................................................................................... 89
AggregatingMessageHandler ..................................................................... 89ReleaseStrategy ....................................................................................... 91Aggregating Large Groups ........................................................................ 93CorrelationStrategy ................................................................................... 93LockRegistry ............................................................................................ 94
Configuring an Aggregator ................................................................................ 94Configuring an Aggregator with XML ......................................................... 94Configuring an Aggregator with Annotations ............................................. 101
Managing State in an Aggregator: MessageGroupStore .................................... 1026.5. Resequencer ................................................................................................... 104
Introduction .................................................................................................... 104Functionality ................................................................................................... 104Configuring a Resequencer ............................................................................. 104
6.6. Message Handler Chain ................................................................................... 106Introduction .................................................................................................... 106Configuring a Chain ........................................................................................ 107
6.7. Scatter-Gather ................................................................................................. 109Introduction .................................................................................................... 109Functionality ................................................................................................... 110Configuring a Scatter-Gather Endpoint ............................................................. 110
6.8. Thread Barrier ................................................................................................. 1127. Message Transformation ............................................................................................. 115
7.1. Transformer ..................................................................................................... 115Introduction .................................................................................................... 115Configuring Transformer ................................................................................. 115
Configuring Transformer with XML ........................................................... 115Common Transformers ........................................................................... 116Configuring a Transformer with Annotations ............................................. 121
Header Filter .................................................................................................. 122Codec-Based Transformers ............................................................................. 122
7.2. Content Enricher .............................................................................................. 122Introduction .................................................................................................... 122Header Enricher ............................................................................................. 122
Configuring a Header Enricher with Java Configuration ............................. 124Configuring a Header Enricher with the Java DSL .................................... 124Header Channel Registry ........................................................................ 124
Payload Enricher ............................................................................................ 125
-
Spring Integration Reference Manual
5.0.7.RELEASE Spring Integration vii
Configuration .......................................................................................... 126Examples ............................................................................................... 128
7.3. Claim Check .................................................................................................... 129Introduction .................................................................................................... 129Incoming Claim Check Transformer ................................................................. 129Outgoing Claim Check Transformer ................................................................. 130A word on Message Store .............................................................................. 131
7.4. Codec ............................................................................................................. 132Introduction .................................................................................................... 132EncodingPayloadTransformer .......................................................................... 132DecodingTransformer ...................................................................................... 132CodecMessageConverter ................................................................................ 132Kryo ............................................................................................................... 132
Customizing Kryo ................................................................................... 1328. Messaging Endpoints .................................................................................................. 135
8.1. Message Endpoints ......................................................................................... 135Message Handler ........................................................................................... 135Event Driven Consumer .................................................................................. 135Polling Consumer ........................................................................................... 136Endpoint Namespace Support ......................................................................... 137Change Polling Rate at Runtime ..................................................................... 141Payload Type Conversion ............................................................................... 142Content Type Conversion ............................................................................... 143Asynchronous polling ...................................................................................... 144Endpoint Inner Beans ..................................................................................... 145
8.2. Endpoint Roles ................................................................................................ 1458.3. Leadership Event Handling ............................................................................... 1478.4. Messaging Gateways ....................................................................................... 147
Enter the GatewayProxyFactoryBean ............................................................... 148Gateway XML Namespace Support ................................................................. 148Setting the Default Reply Channel ................................................................... 148Gateway Configuration with Annotations and/or XML ........................................ 149Mapping Method Arguments to a Message ...................................................... 150@MessagingGateway Annotation .................................................................... 152Invoking No-Argument Methods ....................................................................... 153Error Handling ................................................................................................ 153Gateway Timeouts .......................................................................................... 155Asynchronous Gateway .................................................................................. 156
Introduction ............................................................................................ 156ListenableFuture ..................................................................................... 157AsyncTaskExecutor ................................................................................ 157CompletableFuture ................................................................................. 158Reactor Mono ........................................................................................ 159
Gateway behavior when no response arrives ................................................... 1608.5. Service Activator .............................................................................................. 161
Introduction .................................................................................................... 161Configuring Service Activator .......................................................................... 162Asynchronous Service Activator ...................................................................... 164
8.6. Delayer ........................................................................................................... 164Introduction .................................................................................................... 164
-
Spring Integration Reference Manual
5.0.7.RELEASE Spring Integration viii
Configuring a Delayer ..................................................................................... 165Delayer and a Message Store ......................................................................... 167
8.7. Scripting support .............................................................................................. 168Script configuration ......................................................................................... 168
8.8. Groovy support ................................................................................................ 171Groovy configuration ....................................................................................... 171Control Bus .................................................................................................... 173
8.9. Adding Behavior to Endpoints .......................................................................... 173Introduction .................................................................................................... 173Provided Advice Classes ................................................................................ 174
Retry Advice .......................................................................................... 174Circuit Breaker Advice ............................................................................ 180Expression Evaluating Advice .................................................................. 181
Custom Advice Classes .................................................................................. 182Other Advice Chain Elements ......................................................................... 183Handle Message Advice ................................................................................. 184Transaction Support ....................................................................................... 184Advising Filters ............................................................................................... 186Advising Endpoints Using Annotations ............................................................. 186Ordering Advices within an Advice Chain ......................................................... 186Advised Handler Properties ............................................................................. 186Idempotent Receiver Enterprise Integration Pattern .......................................... 187
8.10. Logging Channel Adapter ............................................................................... 189Configuring with Java Configuration ................................................................. 189Configuring with the Java DSL ........................................................................ 190
9. Java DSL ................................................................................................................... 1919.1. Example Configurations ................................................................................... 1919.2. Introduction ..................................................................................................... 1919.3. DSL Basics ..................................................................................................... 1929.4. Message Channels .......................................................................................... 1939.5. Pollers ............................................................................................................. 1949.6. DSL and Endpoint Configuration ....................................................................... 1959.7. Transformers ................................................................................................... 1959.8. Inbound Channel Adapters ............................................................................... 1959.9. Message Routers ............................................................................................. 1969.10. Splitters ......................................................................................................... 1979.11. Aggregators and Resequencers ...................................................................... 1979.12. ServiceActivators (.handle()) ........................................................................... 1989.13. Operator log() ................................................................................................ 1999.14. MessageChannelSpec.wireTap() ..................................................................... 1999.15. Working With Message Flows ......................................................................... 2009.16. FunctionExpression ........................................................................................ 2019.17. Sub Flows support ......................................................................................... 2019.18. Using Protocol Adapters ................................................................................. 2029.19. IntegrationFlowAdapter ................................................................................... 2049.20. Dynamic and runtime Integration Flows ........................................................... 2059.21. IntegrationFlow as Gateway ........................................................................... 207
10. System Management ................................................................................................ 20910.1. Metrics and Management ............................................................................... 209
Configuring Metrics Capture ............................................................................ 209
-
Spring Integration Reference Manual
5.0.7.RELEASE Spring Integration ix
Micrometer Integration .................................................................................... 210MessageChannel Metric Features ................................................................... 212MessageHandler Metric Features .................................................................... 212Time-Based Average Estimates ....................................................................... 213Metrics Factory ............................................................................................... 213
10.2. JMX Support ................................................................................................. 215Notification Listening Channel Adapter ............................................................. 215Notification Publishing Channel Adapter ........................................................... 216Attribute Polling Channel Adapter .................................................................... 216Tree Polling Channel Adapter ......................................................................... 217Operation Invoking Channel Adapter ............................................................... 217Operation Invoking Outbound Gateway ............................................................ 217MBean Exporter ............................................................................................. 218
MBean ObjectNames .............................................................................. 219JMX Improvements ................................................................................. 220Orderly Shutdown Managed Operation .................................................... 222
10.3. Message History ............................................................................................ 222Message History Configuration ........................................................................ 222
10.4. Message Store .............................................................................................. 224MessageGroupFactory .................................................................................... 226Persistence MessageGroupStore and Lazy-Load .............................................. 226
10.5. Metadata Store .............................................................................................. 226Idempotent Receiver and Metadata Store ........................................................ 227MetadataStoreListener .................................................................................... 228
10.6. Control Bus ................................................................................................... 22810.7. Orderly Shutdown .......................................................................................... 22910.8. Integration Graph ........................................................................................... 230
Graph Runtime Model ..................................................................................... 23310.9. Integration Graph Controller ........................................................................... 234
V. Integration Endpoints .......................................................................................................... 23611. Endpoint Quick Reference Table ............................................................................... 23712. AMQP Support ......................................................................................................... 241
12.1. Introduction .................................................................................................... 24112.2. Inbound Channel Adapter ............................................................................... 241
Configuring with Java Configuration ................................................................. 244Configuring with the Java DSL ........................................................................ 245
12.3. Polled Inbound Channel Adapter ..................................................................... 24612.4. Inbound Gateway ........................................................................................... 246
Configuring with Java Configuration ................................................................. 247Configuring with the Java DSL ........................................................................ 248
12.5. Inbound Endpoint Acknowledge Mode ............................................................. 24912.6. Outbound Channel Adapter ............................................................................ 249
Configuring with Java Configuration ................................................................. 251Configuring with the Java DSL ........................................................................ 252
12.7. Outbound Gateway ........................................................................................ 253Configuring with Java Configuration ................................................................. 255Configuring with the Java DSL ........................................................................ 256
12.8. Async Outbound Gateway .............................................................................. 257Configuring with Java Configuration ................................................................. 259Configuring with the Java DSL ........................................................................ 259
-
Spring Integration Reference Manual
5.0.7.RELEASE Spring Integration x
12.9. Outbound Message Conversion ...................................................................... 26012.10. Outbound User Id ........................................................................................ 26112.11. Delayed Message Exchange ......................................................................... 26112.12. AMQP Backed Message Channels ................................................................ 262
Configuring with Java Configuration ................................................................. 263Configuring with the Java DSL ........................................................................ 263
12.13. AMQP Message Headers ............................................................................. 26412.14. AMQP Samples ........................................................................................... 266
13. Spring ApplicationEvent Support ................................................................................ 26813.1. Receiving Spring Application Events ............................................................... 26813.2. Sending Spring Application Events .................................................................. 268
14. Feed Adapter ........................................................................................................... 27014.1. Introduction .................................................................................................... 27014.2. Feed Inbound Channel Adapter ...................................................................... 27014.3. Java DSL and Annotation configuration ........................................................... 271
15. File Support ............................................................................................................. 27215.1. Introduction .................................................................................................... 27215.2. Reading Files ................................................................................................ 272
Namespace Support ....................................................................................... 275WatchServiceDirectoryScanner ........................................................................ 277Limiting Memory Consumption ........................................................................ 278Configuring with Java Configuration ................................................................. 278Configuring with the Java DSL ........................................................................ 279'Tailing Files .................................................................................................. 279Dealing With Incomplete Data ......................................................................... 281
15.3. Writing files ................................................................................................... 282Generating File Names ................................................................................... 282Specifying the Output Directory ....................................................................... 283Dealing with Existing Destination Files ............................................................. 284Flushing Files When using APPEND_NO_FLUSH ............................................ 285File Timestamps ............................................................................................. 285File Permissions ............................................................................................. 285File Outbound Channel Adapter ...................................................................... 285Outbound Gateway ......................................................................................... 286Configuring with Java Configuration ................................................................. 287Configuring with the Java DSL ........................................................................ 287
15.4. File Transformers ........................................................................................... 28815.5. File Splitter .................................................................................................... 288
Configuring with Java Configuration ................................................................. 290Configuring with the Java DSL ........................................................................ 290
16. FTP/FTPS Adapters .................................................................................................. 29116.1. Introduction .................................................................................................... 29116.2. FTP Session Factory ..................................................................................... 291
Default Factories ............................................................................................ 291FTPS and Shared SSLSession ....................................................................... 293
16.3. Delegating Session Factory ............................................................................ 29416.4. FTP Inbound Channel Adapter ....................................................................... 295
Recovering from Failures ................................................................................ 298Configuring with Java Configuration ................................................................. 299Configuring with the Java DSL ........................................................................ 300
-
Spring Integration Reference Manual
5.0.7.RELEASE Spring Integration xi
Dealing With Incomplete Data ......................................................................... 30116.5. FTP Streaming Inbound Channel Adapter ....................................................... 301
Configuring with Java Configuration ................................................................. 30216.6. Inbound Channel Adapters: Polling Multiple Servers and Directories .................. 30316.7. Inbound Channel Adapters: Controlling Remote File Fetching ........................... 30516.8. FTP Outbound Channel Adapter ..................................................................... 306
Configuring with Java Configuration ................................................................. 307Configuring with the Java DSL ........................................................................ 308
16.9. FTP Outbound Gateway ................................................................................. 309Configuring with Java Configuration ................................................................. 314Configuring with the Java DSL ........................................................................ 315Outbound Gateway Partial Success (mget and mput) ....................................... 315
16.10. FTP Session Caching ................................................................................... 31616.11. RemoteFileTemplate .................................................................................... 31716.12. MessageSessionCallback ............................................................................. 317
17. GemFire Support ...................................................................................................... 31917.1. Introduction .................................................................................................... 31917.2. Inbound Channel Adapter ............................................................................... 31917.3. Continuous Query Inbound Channel Adapter ................................................... 31917.4. Outbound Channel Adapter ............................................................................ 32017.5. Gemfire Message Store ................................................................................. 32117.6. Gemfire Lock Registry .................................................................................... 32217.7. Gemfire Metadata Store ................................................................................. 322
18. HTTP Support .......................................................................................................... 32418.1. Introduction .................................................................................................... 32418.2. Http Inbound Components .............................................................................. 32418.3. Http Outbound Components ........................................................................... 326
HttpRequestExecutingMessageHandler ............................................................ 32618.4. HTTP Namespace Support ............................................................................. 327
Introduction .................................................................................................... 327Inbound .......................................................................................................... 327Request Mapping Support ............................................................................... 328Cross-Origin Resource Sharing (CORS) Support .............................................. 329Response StatusCode .................................................................................... 330URI Template Variables and Expressions ........................................................ 331Outbound ....................................................................................................... 331Mapping URI Variables ................................................................................... 333Controlling URI Encoding ................................................................................ 335
18.5. Configuring HTTP Endpoints with Java ........................................................... 33518.6. Timeout Handling ........................................................................................... 33618.7. HTTP Proxy configuration ............................................................................... 33818.8. HTTP Header Mappings ................................................................................. 33918.9. Integration Graph Controller ........................................................................... 34018.10. HTTP Samples ............................................................................................ 340
Multipart HTTP request - RestTemplate (client) and Http Inbound Gateway(server) .......................................................................................................... 340
19. JDBC Support .......................................................................................................... 34219.1. Inbound Channel Adapter ............................................................................... 342
Polling and Transactions ................................................................................. 344Max-rows-per-poll versus Max-messages-per-poll ............................................. 344
-
Spring Integration Reference Manual
5.0.7.RELEASE Spring Integration xii
19.2. Outbound Channel Adapter ............................................................................ 34519.3. Outbound Gateway ........................................................................................ 34619.4. JDBC Message Store ..................................................................................... 347
Initializing the Database .................................................................................. 348The Generic JDBC Message Store .................................................................. 348Backing Message Channels ............................................................................ 348Partitioning a Message Store .......................................................................... 351
19.5. Stored Procedures ......................................................................................... 351Supported Databases ..................................................................................... 351Configuration .................................................................................................. 352Common Configuration Attributes .................................................................... 352Common Configuration Sub-Elements ............................................................. 354Defining Parameter Sources ........................................................................... 355Stored Procedure Inbound Channel Adapter .................................................... 356Stored Procedure Outbound Channel Adapter .................................................. 357Stored Procedure Outbound Gateway .............................................................. 357Examples ....................................................................................................... 358
19.6. JDBC Lock Registry ....................................................................................... 35919.7. JDBC Metadata Store .................................................................................... 359
20. JPA Support ............................................................................................................. 36120.1. Supported Persistence Providers .................................................................... 36120.2. Java Implementation ...................................................................................... 36220.3. Namespace Support ....................................................................................... 362
Common XML Namespace Configuration Attributes .......................................... 362Providing JPA Query Parameters .................................................................... 364Transaction Handling ...................................................................................... 364
20.4. Inbound Channel Adapter ............................................................................... 365Configuration Parameter Reference ................................................................. 366Configuring with Java Configuration ................................................................. 367Configuring with the Java DSL ........................................................................ 367
20.5. Outbound Channel Adapter ............................................................................ 368Using an Entity Class ..................................................................................... 368Using JPA Query Language (JPA QL) ............................................................. 369Using Native Queries ...................................................................................... 370Using Named Queries .................................................................................... 370Configuration Parameter Reference ................................................................. 371Configuring with Java Configuration ................................................................. 372Configuring with the Java DSL ........................................................................ 373
20.6. Outbound Gateways ....................................................................................... 374Common Configuration Parameters ................................................................. 375Updating Outbound Gateway .......................................................................... 376Configuring with Java Configuration ................................................................. 376Configuring with the Java DSL ........................................................................ 377Retrieving Outbound Gateway ......................................................................... 378Configuring with Java Configuration ................................................................. 378Configuring with the Java DSL ........................................................................ 379JPA Outbound Gateway Samples .................................................................... 380
21. JMS Support ............................................................................................................ 38221.1. Inbound Channel Adapter ............................................................................... 382
Transactions ................................................................................................... 383
-
Spring Integration Reference Manual
5.0.7.RELEASE Spring Integration xiii
21.2. Message-Driven Channel Adapter ................................................................... 383Inbound Conversion Errors ............................................................................. 384
21.3. Outbound Channel Adapter ............................................................................ 385Transactions ................................................................................................... 385
21.4. Inbound Gateway ........................................................................................... 38521.5. Outbound Gateway ........................................................................................ 387
Gateway Reply Correlation ............................................................................. 388Async Gateway .............................................................................................. 390Attribute Reference ......................................................................................... 391
21.6. Mapping Message Headers to/from JMS Message ........................................... 39321.7. Message Conversion, Marshalling and Unmarshalling ...................................... 39321.8. JMS Backed Message Channels ..................................................................... 39421.9. Using JMS Message Selectors ....................................................................... 39521.10. JMS Samples .............................................................................................. 396
22. Mail Support ............................................................................................................. 39722.1. Mail-Sending Channel Adapter ....................................................................... 39722.2. Mail-Receiving Channel Adapter ..................................................................... 39722.3. Inbound Mail Message Mapping ..................................................................... 39822.4. Mail Namespace Support ............................................................................... 39922.5. Marking IMAP Messages When \Recent is Not Supported ................................ 40322.6. Email Message Filtering ................................................................................. 40322.7. Transaction Synchronization ........................................................................... 404
23. MongoDb Support ..................................................................................................... 40623.1. Introduction .................................................................................................... 40623.2. Connecting to MongoDb ................................................................................. 40623.3. MongoDB Message Store ............................................................................... 407
MongoDB Channel Message Store .................................................................. 407MongoDB Metadata Store ............................................................................... 408
23.4. MongoDB Inbound Channel Adapter ............................................................... 40923.5. MongoDB Outbound Channel Adapter ............................................................. 41123.6. MongoDB Outbound Gateway ........................................................................ 411
Configuring with Java Configuration ................................................................. 412Configuring with the Java DSL ........................................................................ 412
24. MQTT Support ......................................................................................................... 41424.1. Introduction .................................................................................................... 41424.2. Inbound (message-driven) Channel Adapter .................................................... 414
Adding/Removing Topics at Runtime ............................................................... 416Configuring with Java Configuration ................................................................. 416
24.3. Outbound Channel Adapter ............................................................................ 417Configuring with Java Configuration ................................................................. 418
25. Redis Support .......................................................................................................... 41925.1. Introduction .................................................................................................... 41925.2. Connecting to Redis ....................................................................................... 41925.3. Messaging with Redis .................................................................................... 420
Redis Publish/Subscribe channel ..................................................................... 420Redis Inbound Channel Adapter ...................................................................... 420Redis Outbound Channel Adapter ................................................................... 421Redis Queue Inbound Channel Adapter ........................................................... 422Redis Queue Outbound Channel Adapter ........................................................ 423Redis Application Events ................................................................................ 423
-
Spring Integration Reference Manual
5.0.7.RELEASE Spring Integration xiv
25.4. Redis Message Store ..................................................................................... 424Redis Channel Message Stores ...................................................................... 424
25.5. Redis Metadata Store .................................................................................... 42525.6. RedisStore Inbound Channel Adapter ............................................................. 42625.7. RedisStore Outbound Channel Adapter ........................................................... 42825.8. Redis Outbound Command Gateway .............................................................. 42925.9. Redis Queue Outbound Gateway .................................................................... 43025.10. Redis Queue Inbound Gateway .................................................................... 43025.11. Redis Lock Registry ..................................................................................... 431
26. Resource Support ..................................................................................................... 43326.1. Introduction .................................................................................................... 43326.2. Resource Inbound Channel Adapter ................................................................ 433
27. RMI Support ............................................................................................................. 43527.1. Introduction .................................................................................................... 43527.2. Outbound RMI ............................................................................................... 43527.3. Inbound RMI .................................................................................................. 43527.4. RMI namespace support ................................................................................ 43527.5. Configuring with Java Configuration ................................................................ 436
28. SFTP Adapters ......................................................................................................... 43728.1. Introduction .................................................................................................... 43728.2. SFTP Session Factory ................................................................................... 437
Configuration Properties .................................................................................. 43828.3. Proxy Factory Bean ....................................................................................... 44028.4. Delegating Session Factory ............................................................................ 44028.5. SFTP Session Caching .................................................................................. 44128.6. RemoteFileTemplate ...................................................................................... 44128.7. SFTP Inbound Channel Adapter ..................................................................... 442
Recovering from Failures ................................................................................ 444Configuring with Java Configuration ................................................................. 445Configuring with the Java DSL ........................................................................ 446Dealing With Incomplete Data ......................................................................... 447
28.8. SFTP Streaming Inbound Channel Adapter ..................................................... 447Configuring with Java Configuration ................................................................. 448
28.9. Inbound Channel Adapters: Polling Multiple Servers and Directories .................. 44928.10. Inbound Channel Adapters: Controlling Remote File Fetching .......................... 45128.11. SFTP Outbound Channel Adapter ................................................................. 452
Configuring with Java Configuration ................................................................. 453Configuring with the Java DSL ........................................................................ 453
28.12. SFTP Outbound Gateway ............................................................................. 454Configuring with Java Configuration ................................................................. 459Configuring with the Java DSL ........................................................................ 459Outbound Gateway Partial Success (mget and mput) ....................................... 460
28.13. SFTP/JSCH Logging .................................................................................... 46128.14. MessageSessionCallback ............................................................................. 461
29. STOMP Support ....................................................................................................... 46229.1. Introduction .................................................................................................... 46229.2. Overview ....................................................................................................... 46229.3. STOMP Inbound Channel Adapter .................................................................. 46229.4. STOMP Outbound Channel Adapter ............................................................... 46229.5. STOMP Headers Mapping .............................................................................. 463
-
Spring Integration Reference Manual
5.0.7.RELEASE Spring Integration xv
29.6. STOMP Integration Events ............................................................................. 46329.7. STOMP Adapters Java Configuration .............................................................. 46429.8. STOMP Namespace Support .......................................................................... 465
30. Stream Support ........................................................................................................ 46730.1. Introduction .................................................................................................... 46730.2. Reading from streams .................................................................................... 46730.3. Writing to streams .......................................................................................... 46830.4. Stream namespace support ............................................................................ 468
31. Syslog Support ......................................................................................................... 47031.1. Introduction .................................................................................................... 47031.2. Syslog ................................................................. 470
Example Configuration .................................................................................... 47032. TCP and UDP Support ............................................................................................. 473
32.1. Introduction .................................................................................................... 47332.2. UDP Adapters ............................................................................................... 473
Outbound (XML Configuration) ........................................................................ 473Outbound (Java Configuration) ........................................................................ 475Outbound (Java DSL Configuration) ................................................................ 475Inbound (XML Configuration) ........................................................................... 475Inbound (Java Configuration) .......................................................................... 475Inbound (Java DSL Configuration) ................................................................... 475Server Listening Events .................................................................................. 476Advanced Outbound Configuration .................................................................. 476
32.3. TCP Connection Factories .............................................................................. 476TCP Caching Client Connection Factory .......................................................... 480TCP Failover Client Connection Factory .......................................................... 481TCP Thread Affinity Connection Factory .......................................................... 481
32.4. TCP Connection Interceptors .......................................................................... 48132.5. TCP Connection Events ................................................................................. 48232.6. TCP Adapters ................................................................................................ 48332.7. TCP Gateways .............................................................................................. 48532.8. TCP Message Correlation .............................................................................. 486
Overview ........................................................................................................ 486Gateways ....................................................................................................... 486Collaborating Outbound and Inbound Channel Adapters ................................... 486Transferring Headers ...................................................................................... 487
32.9. A Note About NIO .......................................................................................... 489Thread Pool Task Executor with CALLER_RUNS Policy ................................... 489
32.10. SSL/TLS Support ......................................................................................... 491Overview ........................................................................................................ 491Getting Started ............................................................................................... 491
32.11. Advanced Techniques .................................................................................. 492Strategy Interfaces ......................................................................................... 492Example: Enabling SSL Client Authentication ................................................... 494
32.12. IP Configuration Attributes ............................................................................ 49532.13. IP Message Headers .................................................................................... 50232.14. Annotation-Based Configuration .................................................................... 503
33. Twitter Support ......................................................................................................... 50633.1. Introduction .................................................................................................... 50633.2. Twitter OAuth Configuration ............................................................................ 506
-
Spring Integration Reference Manual
5.0.7.RELEASE Spring Integration xvi
33.3. Twitter Template ............................................................................................ 50633.4. Twitter Inbound Adapters ............................................................................... 507
Inbound Message Channel Adapter ................................................................. 508Direct Inbound Message Channel Adapter ....................................................... 508Mentions Inbound Message Channel Adapter .................................................. 508Search Inbound Message Channel Adapter ..................................................... 508
33.5. Twitter Outbound Adapter ............................................................................... 509Twitter Outbound Update Channel Adapter ...................................................... 509Twitter Outbound Direct Message Channel Adapter .......................................... 510
33.6. Twitter Search Outbound Gateway .................................................................. 51034. WebFlux Support ...................................................................................................... 512
34.1. Introduction .................................................................................................... 51234.2. WebFlux Inbound Components ....................................................................... 51234.3. WebFlux Outbound Components .................................................................... 51334.4. WebFlux Namespace Support ........................................................................ 514
Introduction .................................................................................................... 514Inbound .......................................................................................................... 514Outbound ....................................................................................................... 515
34.5. Configuring WebFlux Endpoints with Java ....................................................... 51534.6. WebFlux Header Mappings ............................................................................ 516
35. WebSockets Support ................................................................................................ 51735.1. Introduction .................................................................................................... 51735.2. Overview ....................................................................................................... 51735.3. WebSocket Inbound Channel Adapter ............................................................. 51835.4. WebSocket Outbound Channel Adapter .......................................................... 51935.5. WebSockets Namespace Support ................................................................... 52035.6. ClientStompEncoder ....................................................................................... 523
36. Web Services Support .............................................................................................. 52536.1. Outbound Web Service Gateways ................................................................... 52536.2. Inbound Web Service Gateways ..................................................................... 52536.3. Web Service Namespace Support ................................................................... 52636.4. Outbound URI Configuration ........................................................................... 52736.5. WS Message Headers ................................................................................... 52836.6. MTOM Support .............................................................................................. 529
37. XML Support - Dealing with XML Payloads ................................................................ 53137.1. Introduction .................................................................................................... 53137.2. Namespace Support ....................................................................................... 531
XPath Expressions ......................................................................................... 532Providing Namespaces (Optional) to XPath Expressions ........................... 532Using XPath Expressions with Default Namespaces ................................. 533
37.3. Transforming XML Payloads ........................................................................... 534Configuring Transformers as Beans ................................................................. 534
UnmarshallingTransformer ...................................................................... 535MarshallingTransformer ........................................................................... 535XsltPayloadTransformer .......................................................................... 536ResultTransformers ................................................................................. 536
Namespace Support for XML Transformers ...................................................... 537Namespace Configuration and ResultTransformers ........................................... 538
37.4. Transforming XML Messages Using XPath ...................................................... 54037.5. Splitting XML Messages ................................................................................. 541
-
Spring Integration Reference Manual
5.0.7.RELEASE Spring Integration xvii
37.6. Routing XML Messages Using XPath .............................................................. 542XML Payload Converter .................................................................................. 544
37.7. XPath Header Enricher .................................................................................. 54437.8. Using the XPath Filter .................................................................................... 54537.9. #xpath SpEL Function .................................................................................... 54637.10. XML Validating Filter .................................................................................... 547
38. XMPP Support ......................................................................................................... 54838.1. Introduction .................................................................................................... 54838.2. XMPP Connection .......................................................................................... 54838.3. XMPP Messages ........................................................................................... 549
Inbound Message Channel Adapter ................................................................. 549Outbound Message Channel Adapter .............................................................. 550
38.4. XMPP Presence ............................................................................................ 550Inbound Presence Message Channel Adapter .................................................. 550Outbound Presence Message Channel Adapter ............................................... 551
38.5. Advanced Configuration ................................................................................. 55138.6. XMPP Message Headers ............................................................................... 55238.7. XMPP Extensions .......................................................................................... 553
39. Zookeeper Support ................................................................................................... 55539.1. Introduction .................................................................................................... 55539.2. Zookeeper Metadata Store ............................................................................. 55539.3. Zookeeper Lock Registry ................................................................................ 55539.4. Zookeeper Leadership Event Handling ............................................................ 555
VI. Appendices ....................................................................................................................... 557A. Spring Expression Language (SpEL) ........................................................................... 558
A.1. Introduction ..................................................................................................... 558A.2. SpEL Evaluation Context Customization ........................................................... 558A.3. SpEL Functions ............................................................................................... 559A.4. PropertyAccessors ........................................................................................... 560
B. Message Publishing ................................................................................................... 562B.1. Message Publishing Configuration .................................................................... 562
Annotation-driven approach via @Publisher annotation ..................................... 562XML-based approach via the element .......................... 564Producing and publishing messages based on a scheduled trigger .................... 566
C. Transaction Support ................................................................................................... 568C.1. Understanding Transactions in Message flows .................................................. 568
Poller Transaction Support .............................................................................. 569C.2. Transaction Boundaries ................................................................................... 570C.3. Transaction Synchronization ............................................................................ 570C.4. Pseudo Transactions ....................................................................................... 572
D. Security in Spring Integration ...................................................................................... 574D.1. Introduction ..................................................................................................... 574D.2. Securing channels ........................................................................................... 574D.3. SecurityContext Propagation ............................................................................ 575
E. Configuration ............................................................................................................. 578E.1. Introduction ..................................................................................................... 578E.2. Namespace Support ........................................................................................ 578E.3. Configuring the Task Scheduler ....................................................................... 579E.4. Error Handling ................................................................................................. 580E.5. Global Properties ............................................................................................. 581
-
Spring Integration Reference Manual
5.0.7.RELEASE Spring Integration xviii
E.6. Annotation Support .......................................................................................... 582Messaging Meta-Annotations .......................................................................... 587Annotations on @Beans ................................................................................. 587Creating a Bridge with Annotations .................................................................. 589Advising Annotated Endpoints ......................................................................... 590
E.7. Message Mapping rules and conventions .......................................................... 590Simple Scenarios ............................................................................................ 590Complex Scenarios ......................................................................................... 592
F. Testing support .......................................................................................................... 594F.1. Introduction ..................................................................................................... 594F.2. Testing Utilities ................................................................................................ 595
TestUtils ......................................................................................................... 595SocketUtils ..................................................................................................... 595OnlyOnceTrigger ............................................................................................ 596Support Components ...................................................................................... 596Hamcrest and Mockito Matchers ..................................................................... 596
F.3. Spring Integration and test context ................................................................... 597F.4. Integration Mocks ............................................................................................ 598
MockIntegration .............................................................................................. 598F.5. Other Resources ............................................................................................. 599
G. Spring Integration Samples ........................................................................................ 600G.1. Introduction ..................................................................................................... 600G.2. Where to get Samples .................................................................................... 600G.3. Submitting Samples or Sample Requests ......................................................... 600G.4. Samples Structure ........................................................................................... 601G.5. Samples ......................................................................................................... 602
Loan Broker ................................................................................................... 603The Cafe Sample ........................................................................................... 607The XML Messaging Sample .......................................................................... 611
H. Additional Resources ................................................................................................. 612H.1. Spring Integration Home ............