Skip to content

Commit b92d52f

Browse files
committed
Improve docs for global default poller
* Fix Kotlin deprecation warning in the test * Replace wrong `IntervalTrigger` mentioning in the docs to the proper `PeriodicTrigger` * Fix code snippet in the `channel-adapter.adoc`
1 parent 0fb64f1 commit b92d52f

File tree

3 files changed

+77
-12
lines changed

3 files changed

+77
-12
lines changed

spring-integration-core/src/test/kotlin/org/springframework/integration/dsl/KotlinDslTests.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ class KotlinDslTests {
258258
@Bean
259259
fun functionFlow2() =
260260
integrationFlow<Function<*, *>> {
261-
transform<String> { it.toLowerCase() }
261+
transform<String> { it.lowercase() }
262262
filter(UnexpiredMessageSelector())
263263
route<Message<*>, Any?>({ null }) { defaultOutputToParentFlow() }
264264
route<Message<*>> { m -> m.headers.replyChannel }

src/reference/asciidoc/channel-adapter.adoc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ However, if you are sure that your method can return null and you need to poll f
124124
====
125125
126126
Starting with version 5.5, a `0` value for `max-messages-per-poll` has a special meaning - skip the `MessageSource.receive()` call altogether, which may be considered as pausing for this inbound channel adapter until the `maxMessagesPerPoll` is changed to a non-zero value at a later time, e.g. via a Control Bus.
127+
128+
Also see <<./endpoint.adoc#global-default-poller>> for more information.
127129
=====
128130

129131
[[channel-adapter-namespace-outbound]]
@@ -175,7 +177,6 @@ fun outboundChannelAdapterFlow(myPojo: MyPojo) =
175177
If the channel being adapted is a `PollableChannel`, you must provide a poller sub-element (the `@Poller` sub-annotation on the `@ServiceActivator`), as the following example shows:
176178

177179
====
178-
----
179180
[source, java, role="primary"]
180181
.Java
181182
----

src/reference/asciidoc/endpoint.adoc

Lines changed: 74 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -95,18 +95,17 @@ The following example shows how to set the trigger:
9595
----
9696
PollingConsumer consumer = new PollingConsumer(channel, handler);
9797
98-
consumer.setTrigger(new IntervalTrigger(30, TimeUnit.SECONDS));
98+
consumer.setTrigger(new PeriodicTrigger(30, TimeUnit.SECONDS));
9999
----
100100
====
101101

102-
Spring Integration currently provides two implementations of the `Trigger` interface: `IntervalTrigger` and `CronTrigger`.
103-
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` -- that is, no fixed delay).
102+
The `PeriodicTrigger` is typically defined with a simple interval (in milliseconds) but also supports an `initialDelay` property and a boolean `fixedRate` property (the default is `false` -- that is, no fixed delay).
104103
The following example sets both properties:
105104

106105
====
107106
[source,java]
108107
----
109-
IntervalTrigger trigger = new IntervalTrigger(1000);
108+
PeriodicTrigger trigger = new PeriodicTrigger(1000);
110109
trigger.setInitialDelay(5000);
111110
trigger.setFixedRate(true);
112111
----
@@ -316,22 +315,87 @@ It is also possible to create top-level pollers, in which case only a `ref` attr
316315
NOTE: The `ref` attribute is allowed only on the inner poller definitions.
317316
Defining this attribute on a top-level poller results in a configuration exception being thrown during initialization of the application context.
318317

319-
====== Global Default Pollers
318+
[[global-default-poller]]
319+
====== Global Default Poller
320320

321321
To simplify the configuration even further, you can define a global default poller.
322-
A single top-level poller within an `ApplicationContext` may have the `default` attribute set to `true`.
323-
In that case, any endpoint with a `PollableChannel` for its input channel, that is defined within the same `ApplicationContext`, and has no explicitly configured `poller` sub-element uses that default.
322+
A single top-level poller component in XML DSL may have the `default` attribute set to `true`.
323+
For Java configuration a `PollerMetadata` bean with the `PollerMetadata.DEFAULT_POLLER` name must be declared in this case.
324+
In that case, any endpoint with a `PollableChannel` for its input channel, that is defined within the same `ApplicationContext`, and has no explicitly configured `poller` uses that default.
324325
The following example shows such a poller and a transformer that uses it:
325326

326-
[source,xml]
327+
328+
====
329+
[source, java, role="primary"]
330+
.Java DSL
327331
----
328-
<int:poller id="defaultPoller" default="true" max-messages-per-poll="5" fixed-rate="3000"/>
332+
@Bean(name = PollerMetadata.DEFAULT_POLLER)
333+
public PollerMetadata defaultPoller() {
334+
PollerMetadata pollerMetadata = new PollerMetadata();
335+
pollerMetadata.setMaxMessagesPerPoll(5);
336+
pollerMetadata.setTrigger(new PeriodicTrigger(3000));
337+
return pollerMetadata;
338+
}
339+
340+
// No 'poller' attribute because there is a default global poller
341+
@Bean
342+
public IntegrationFlow transformFlow(MyTransformer transformer) {
343+
return IntegrationFlows.from(MessageChannels.queue("pollable"))
344+
.transform(transformer) // No 'poller' attribute because there is a default global poller
345+
.channel("output")
346+
.get();
347+
}
348+
----
349+
[source, java, role="secondary"]
350+
.Java
351+
----
352+
@Bean(PollerMetadata.DEFAULT_POLLER)
353+
public PollerMetadata defaultPoller() {
354+
PollerMetadata pollerMetadata = new PollerMetadata();
355+
pollerMetadata.setMaxMessagesPerPoll(5);
356+
pollerMetadata.setTrigger(new PeriodicTrigger(3000));
357+
return pollerMetadata;
358+
}
359+
360+
@Bean
361+
public QueueChannel pollable() {
362+
return new QueueChannel();
363+
}
364+
// No 'poller' attribute because there is a default global poller
365+
@Transformer(inputChannel = "pollable", outputChannel = "output")
366+
public Object transform(Object payload) {
367+
...
368+
}
369+
----
370+
[source, kotlin, role="secondary"]
371+
.Kotlin DSL
372+
----
373+
@Bean(PollerMetadata.DEFAULT_POLLER)
374+
fun defaultPoller() =
375+
PollerMetadata()
376+
.also {
377+
it.maxMessagesPerPoll = 5
378+
it.trigger = PeriodicTrigger(3000)
379+
}
380+
381+
@Bean
382+
fun convertFlow() =
383+
integrationFlow(MessageChannels.queue("pollable")) {
384+
transform(transformer) // No 'poller' attribute because there is a default global poller
385+
channel("output")
386+
}
387+
----
388+
[source, xml, role="secondary"]
389+
.XML
390+
----
391+
<int:poller id="defaultPoller" default="true" max-messages-per-poll="5" fixed-delay="3000"/>
329392
330393
<!-- No <poller/> sub-element is necessary, because there is a default -->
331394
<int:transformer input-channel="pollable"
332395
ref="transformer"
333396
output-channel="output"/>
334397
----
398+
====
335399

336400
[[transaction-support]]
337401
====== Transaction Support
@@ -412,7 +476,7 @@ You should also keep in mind that the `task-executor` attribute can provide a re
412476
The `executor` element shown earlier is provided for convenience.
413477

414478
As mentioned earlier in the <<endpoint-pollingconsumer,background section for polling consumers>>, you can also configure a polling consumer in such a way as to emulate event-driven behavior.
415-
With a long `receive-timeout` and a short `interval-trigger`, you can ensure a very timely reaction to arriving messages even on a polled message source.
479+
With a long receive timeout and a short interval in the trigger, you can ensure a very timely reaction to arriving messages even on a polled message source.
416480
Note that this applies only to sources that have a blocking wait call with a timeout.
417481
For example, the file poller does not block.
418482
Each `receive()` call returns immediately and either contains new files or not.

0 commit comments

Comments
 (0)