Improve split() DSL (#8666)
* Introduce a `SplitterSpec` which can accept possible splitter variants: `expression`, `function`, `ref` etc. This way we are going to have a complex endpoint configuration only with a single method argument. * Use `SplitterSpec` in a newly introduced `splitWith()` * Deprecate those `split()` methods which use `SplitterEndpointSpec`. This method are complex enough because of their several arguments * Refactor some common `MessageHandler` options initialization into the `ConsumerEndpointSpec.doGet()` * Disable failing now `MethodInvokingMessageProcessorTests.testCollectionArgument()`: or Jackson problem, or fresh SF * Groovy DSL will be fixed in the separate PR: https://stackoverflow.com/questions/76595843/groovy-selects-a-defaultgroovymethods-split-instead-of-mine-one
This commit is contained in:
@@ -1396,7 +1396,7 @@ Consider the following integration flow:
|
||||
@Bean
|
||||
public IntegrationFlow flow(RabbitTemplate template) {
|
||||
return IntegrationFlow.from(Gateway.class)
|
||||
.split(s -> s.delimiters(","))
|
||||
.splitWith(s -> s.delimiters(","))
|
||||
.<String, String>transform(String::toUpperCase)
|
||||
.handle(Amqp.outboundAdapter(template).routingKey("rk"))
|
||||
.get();
|
||||
@@ -1420,7 +1420,7 @@ The following example shows how to use `BoundRabbitChannelAdvice`:
|
||||
@Bean
|
||||
public IntegrationFlow flow(RabbitTemplate template) {
|
||||
return IntegrationFlow.from(Gateway.class)
|
||||
.split(s -> s.delimiters(",")
|
||||
.splitWith(s -> s.delimiters(",")
|
||||
.advice(new BoundRabbitChannelAdvice(template, Duration.ofSeconds(10))))
|
||||
.<String, String>transform(String::toUpperCase)
|
||||
.handle(Amqp.outboundAdapter(template).routingKey("rk"))
|
||||
|
||||
@@ -491,14 +491,14 @@ To create a splitter, use the `split()` EIP method.
|
||||
By default, if the payload is an `Iterable`, an `Iterator`, an `Array`, a `Stream`, or a reactive `Publisher`, the `split()` method outputs each item as an individual message.
|
||||
It accepts a lambda, a SpEL expression, or any `AbstractMessageSplitter` implementation.
|
||||
Alternatively, you can use it without parameters to provide the `DefaultMessageSplitter`.
|
||||
The following example shows how to use the `split()` method by providing a lambda:
|
||||
The following example shows how to use the `splitWith()` method by providing a lambda:
|
||||
|
||||
[source,java]
|
||||
----
|
||||
@Bean
|
||||
public IntegrationFlow splitFlow() {
|
||||
return IntegrationFlow.from("splitInput")
|
||||
.split(s -> s.applySequence(false).delimiters(","))
|
||||
.splitWith(s -> s.applySequence(false).delimiters(","))
|
||||
.channel(MessageChannels.executor(taskExecutor()))
|
||||
.get();
|
||||
}
|
||||
|
||||
@@ -110,7 +110,7 @@ public ProducerFactory<Integer, String> producerFactory() {
|
||||
@Bean
|
||||
public IntegrationFlow sendToKafkaFlow() {
|
||||
return f -> f
|
||||
.<String>split(p -> Stream.generate(() -> p).limit(101).iterator(), null)
|
||||
.splitWith(s -> s.<String>function(p -> Stream.generate(() -> p).limit(101).iterator()))
|
||||
.publishSubscribeChannel(c -> c
|
||||
.subscribe(sf -> sf.handle(
|
||||
kafkaMessageHandler(producerFactory(), TEST_TOPIC1)
|
||||
|
||||
@@ -30,4 +30,4 @@ See <<./debezium.adoc#debezium, Debezium Support>> for more information.
|
||||
See <<./endpoint.adoc#endpoint-pollingconsumer, Polling Consumer>> for more information.
|
||||
|
||||
- Java, Groovy and Kotlin DSLs have now context-specific methods in the `IntegationFlowDefinition` with a single `Consumer` argument to configure an endpoint and its handler with one builder and readable options.
|
||||
See, for example, `transformWith()` in <<./dsl.adoc#java-dsl, Java DSL Chapter>>.
|
||||
See, for example, `transformWith()`, `splitWith()` in <<./dsl.adoc#java-dsl, Java DSL Chapter>>.
|
||||
|
||||
Reference in New Issue
Block a user