From 3ce9a382427a8e2129153c1ec4e8bafa4a0aeded Mon Sep 17 00:00:00 2001 From: Oleg Zhurakousky Date: Tue, 26 Feb 2019 18:55:07 +0100 Subject: [PATCH] GH-1433 Added docs for scheduled task for PollableMessageSource Resolves #1433 --- docs/src/main/asciidoc/spring-cloud-stream.adoc | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/docs/src/main/asciidoc/spring-cloud-stream.adoc b/docs/src/main/asciidoc/spring-cloud-stream.adoc index abc4e923e..9dc6d7835 100644 --- a/docs/src/main/asciidoc/spring-cloud-stream.adoc +++ b/docs/src/main/asciidoc/spring-cloud-stream.adoc @@ -756,6 +756,22 @@ public ApplicationRunner poller(PollableMessageSource destIn, MessageChannel des } ---- +A less manual and more Spring-like alternative would be to configure a scheduled task bean. For example, + +[source,java] +---- + +@Scheduled(fixedDelay = 5_000) +public void poll() { + System.out.println("Polling..."); + this.source.poll(m -> { + System.out.println(m.getPayload()); + + }, new ParameterizedTypeReference() { }); +} +---- + + The `PollableMessageSource.poll()` method takes a `MessageHandler` argument (often a lambda expression, as shown here). It returns `true` if the message was received and successfully processed.