From dadb8af280ab69cd18fd03d7c81e31cc01d75ca0 Mon Sep 17 00:00:00 2001 From: Oleg Zhurakousky Date: Tue, 25 May 2021 12:42:03 +0200 Subject: [PATCH] GH-2143 Add documentation for batch producers Resolves #2143 --- .../main/asciidoc/spring-cloud-stream.adoc | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/docs/src/main/asciidoc/spring-cloud-stream.adoc b/docs/src/main/asciidoc/spring-cloud-stream.adoc index 827f5dd37..c246b5483 100644 --- a/docs/src/main/asciidoc/spring-cloud-stream.adoc +++ b/docs/src/main/asciidoc/spring-cloud-stream.adoc @@ -986,6 +986,30 @@ public Function, Person> findFirstPerson() { } ---- +===== Batch Producers + +You can also use the concept of batching on the producer side by returning a collection of Messages which effectively provides an +inverse effect where each message in the collection will be sent individually by the binder. + +Consider the following function: + +[source, java] +---- +@Bean +public Function>> batch() { + return p -> { + List> list = new ArrayList<>(); + list.add(MessageBuilder.withPayload(p + ":1").build()); + list.add(MessageBuilder.withPayload(p + ":2").build()); + list.add(MessageBuilder.withPayload(p + ":3").build()); + list.add(MessageBuilder.withPayload(p + ":4").build()); + return list; + }; +} +---- + +Each message in the returned list will be sent individually resulting in four messages sent to output destination. + ===== Spring Integration flow as functions When you implement a function, you may have complex requirements that fit the category of https://www.enterpriseintegrationpatterns.com[Enterprise Integration Patterns] (EIP). These are best handled by using a