From 24abdf65b117965b303b785d28d570c403a0cbd7 Mon Sep 17 00:00:00 2001 From: Gunnar Hillert Date: Wed, 20 Jun 2012 17:19:55 -0400 Subject: [PATCH] INT-2444 - Polling Consumer Reference Doc Fix * In Chapter 7.1.3 Polling Consumer - The Java TX Configuration Example for Consumer is incorrect * Add documentation for the adviceChain property * Add references to the Advice Chain and Transaction Support Sections * Fix Layout issues of the code listings For reference: https://jira.springsource.org/browse/INT-2444 --- src/reference/docbook/endpoint.xml | 71 ++++++++++++++++++------------ 1 file changed, 42 insertions(+), 29 deletions(-) diff --git a/src/reference/docbook/endpoint.xml b/src/reference/docbook/endpoint.xml index 72aec1850e..741ccf8b8c 100644 --- a/src/reference/docbook/endpoint.xml +++ b/src/reference/docbook/endpoint.xml @@ -76,42 +76,45 @@ EventDrivenConsumer consumer = new EventDrivenConsumer(channel, exampleHandler); Spring Integration also provides a PollingConsumer, and it can be instantiated in the same way except that the channel must implement PollableChannel: - PollableChannel channel = context.getBean("pollableChannel", PollableChannel.class); + + PollableChannel channel = context.getBean("pollableChannel", PollableChannel.class); PollingConsumer consumer = new PollingConsumer(channel, exampleHandler); - For more information regarding Polling Consumers, please also read as well as . - - There are many other configuration options for the Polling Consumer. For example, the trigger is a required property: - -PollingConsumer consumer = new PollingConsumer(channel, handler); + + There are many other configuration options for the Polling Consumer. For example, the trigger is a required property: + + PollingConsumer consumer = new PollingConsumer(channel, handler); consumer.setTrigger(new IntervalTrigger(30, TimeUnit.SECONDS)); + Spring Integration currently provides two implementations of the Trigger interface: IntervalTrigger and CronTrigger. The IntervalTrigger is typically defined with a simple interval (in milliseconds), but also supports an initialDelay property and a boolean fixedRate property (the default is false, i.e. fixed delay): + IntervalTrigger trigger = new IntervalTrigger(1000); trigger.setInitialDelay(5000); trigger.setFixedRate(true); - The CronTrigger simply requires a valid cron expression (see the Javadoc for details): + + The CronTrigger simply requires a valid cron + expression (see the Javadoc for details): + CronTrigger trigger = new CronTrigger("*/10 * * * * MON-FRI"); - - - In addition to the trigger, several other polling-related configuration properties may be specified: - -PollingConsumer consumer = new PollingConsumer(channel, handler); + + In addition to the trigger, several other polling-related configuration + properties may be specified: + + PollingConsumer consumer = new PollingConsumer(channel, handler); consumer.setMaxMessagesPerPoll(10); - consumer.setReceiveTimeout(5000); - The maxMessagesPerPoll property specifies the maximum number of messages to receive within a given poll operation. This means that the poller will continue calling receive() without waiting @@ -131,22 +134,33 @@ consumer.setReceiveTimeout(5000); option requires a thread to wait, but as a result it is able to respond much more quickly to arriving messages. This technique, known as long polling, can be used to emulate event-driven behavior on a polled source. - - A Polling Consumer may also delegate to a Spring TaskExecutor, and it can - be configured to participate in Spring-managed transactions. The following example shows the configuration of both: - -PollingConsumer consumer = new PollingConsumer(channel, handler); + + A Polling Consumer may also delegate to a Spring TaskExecutor, + as illustrated in the following example: + + PollingConsumer consumer = new PollingConsumer(channel, handler); TaskExecutor taskExecutor = context.getBean("exampleExecutor", TaskExecutor.class); -consumer.setTaskExecutor(taskExecutor); - -PlatformTransactionManager txManager = context.getBean("exampleTxManager", PlatformTransationManager.class); -consumer.setTransactionManager(txManager); - The examples above show dependency lookups, but keep in mind that these consumers will most often be configured - as Spring bean definitions. In fact, Spring Integration also provides a - FactoryBean that creates the appropriate consumer type based on the type of - channel, and there is full XML namespace support to even further hide those details. The namespace-based - configuration will be featured as each component type is introduced. +consumer.setTaskExecutor(taskExecutor); + + Furthermore, a PollingConsumer has a property called + adviceChain. This property allows you to specify a + List of AOP Advices for handling additional + cross cutting concerns including transactions. These advices are applied + around the doPoll() method. For more in-depth + information, please see the sections AOP Advice chains + and Transaction Support under . + + + The examples above show dependency lookups, but keep in mind that these + consumers will most often be configured as Spring bean definitions. + In fact, Spring Integration also provides a FactoryBean + called ConsumerEndpointFactoryBean that creates + the appropriate consumer type based on the type of channel, and there is + full XML namespace support to even further hide those details. The + namespace-based configuration will be featured as each component type is + introduced. + Many of the MessageHandler implementations are also capable of generating reply Messages. As mentioned above, sending Messages is trivial when compared to the Message reception. Nevertheless, @@ -158,7 +172,6 @@ consumer.setTransactionManager(txManager); class, the AbstractReplyProducingMessageHandler, and it provides a setOutputChannel(..) method. -