Fix Groovy DSL for new splitter style (#8669)

* Fix Groovy DSL for new splitter style

* Introduce a new `GroovyIntegrationFlowDefinition.splitWith()`
to avoid clashing with existing method
* Deprecate all other `split()` variants, but left one without arguments
for a default splitting options
* Fix doc for new splitter style

* * Fix tab indentations in `groovy-dsl.adoc`
This commit is contained in:
Artem Bilan
2023-07-10 11:08:44 -04:00
committed by GitHub
parent 34f901f7db
commit 72fc79dbd5
5 changed files with 83 additions and 11 deletions

View File

@@ -47,6 +47,7 @@ import org.springframework.integration.dsl.ResequencerSpec
import org.springframework.integration.dsl.RouterSpec import org.springframework.integration.dsl.RouterSpec
import org.springframework.integration.dsl.ScatterGatherSpec import org.springframework.integration.dsl.ScatterGatherSpec
import org.springframework.integration.dsl.SplitterEndpointSpec import org.springframework.integration.dsl.SplitterEndpointSpec
import org.springframework.integration.dsl.SplitterSpec
import org.springframework.integration.dsl.TransformerEndpointSpec import org.springframework.integration.dsl.TransformerEndpointSpec
import org.springframework.integration.dsl.WireTapSpec import org.springframework.integration.dsl.WireTapSpec
import org.springframework.integration.filter.MethodInvokingSelector import org.springframework.integration.filter.MethodInvokingSelector
@@ -710,18 +711,47 @@ class GroovyIntegrationFlowDefinition {
this this
} }
/**
* Populate the {@link DefaultMessageSplitter} with default options to the current integration flow position.
*/
GroovyIntegrationFlowDefinition split() {
this.delegate.split()
this
}
/** /**
* Populate the {@link DefaultMessageSplitter} with provided options * Populate the {@link DefaultMessageSplitter} with provided options
* to the current integration flow position. * to the current integration flow position.
* Used with a Closure expression (optional). * Used with a Closure expression (optional).
* @param endpointConfigurer the {@link Consumer} to provide integration endpoint options * @param endpointConfigurer the {@link Consumer} to provide integration endpoint options
* and for {@link DefaultMessageSplitter}. * and for {@link DefaultMessageSplitter}.
* @since 6.2
* @see SplitterSpec
*/
GroovyIntegrationFlowDefinition splitWith(
@DelegatesTo(value = SplitterSpec, strategy = Closure.DELEGATE_FIRST)
@ClosureParams(value = SimpleType.class, options = 'org.springframework.integration.dsl.SplitterSpec')
Closure<?> splitConfigurer) {
this.delegate.splitWith createConfigurerIfAny(splitConfigurer)
this
}
/**
* Populate the {@link DefaultMessageSplitter} with provided options
* to the current integration flow position.
* Used with a Closure expression.
* @param endpointConfigurer the {@link Consumer} to provide integration endpoint options
* and for {@link DefaultMessageSplitter}.
* @deprecated since 6.2 in favor of {@link #splitWith(groovy.lang.Closure)}
* @see SplitterEndpointSpec * @see SplitterEndpointSpec
*/ */
@Deprecated(since = '6.2', forRemoval = true)
@SuppressWarnings(['removal', 'deprecation'])
GroovyIntegrationFlowDefinition split( GroovyIntegrationFlowDefinition split(
@DelegatesTo(value = SplitterEndpointSpec<DefaultMessageSplitter>, strategy = Closure.DELEGATE_FIRST) @DelegatesTo(value = SplitterEndpointSpec<DefaultMessageSplitter>, strategy = Closure.DELEGATE_FIRST)
@ClosureParams(value = SimpleType.class, options = 'org.springframework.integration.dsl.SplitterEndpointSpec') @ClosureParams(value = SimpleType.class, options = 'org.springframework.integration.dsl.SplitterEndpointSpec')
Closure<?> endpointConfigurer = null) { Closure<?> endpointConfigurer) {
this.delegate.split createConfigurerIfAny(endpointConfigurer) this.delegate.split createConfigurerIfAny(endpointConfigurer)
this this
@@ -733,7 +763,10 @@ class GroovyIntegrationFlowDefinition {
* @param expression the splitter SpEL expression. * @param expression the splitter SpEL expression.
* @param endpointConfigurer the {@link Consumer} to provide integration endpoint options * @param endpointConfigurer the {@link Consumer} to provide integration endpoint options
* and for {@link ExpressionEvaluatingSplitter}. * and for {@link ExpressionEvaluatingSplitter}.
* @deprecated since 6.2 in favor of {@link #splitWith(groovy.lang.Closure)}
*/ */
@Deprecated(since = '6.2', forRemoval = true)
@SuppressWarnings(['removal', 'deprecation'])
GroovyIntegrationFlowDefinition split( GroovyIntegrationFlowDefinition split(
String expression, String expression,
@DelegatesTo(value = SplitterEndpointSpec<ExpressionEvaluatingSplitter>, strategy = Closure.DELEGATE_FIRST) @DelegatesTo(value = SplitterEndpointSpec<ExpressionEvaluatingSplitter>, strategy = Closure.DELEGATE_FIRST)
@@ -752,7 +785,10 @@ class GroovyIntegrationFlowDefinition {
* @param methodName the method to invoke. * @param methodName the method to invoke.
* @param endpointConfigurer the {@link Consumer} to provide integration endpoint options * @param endpointConfigurer the {@link Consumer} to provide integration endpoint options
* and for {@link MethodInvokingSplitter}. * and for {@link MethodInvokingSplitter}.
* @deprecated since 6.2 in favor of {@link #splitWith(groovy.lang.Closure)}
*/ */
@Deprecated(since = '6.2', forRemoval = true)
@SuppressWarnings(['removal', 'deprecation'])
GroovyIntegrationFlowDefinition split( GroovyIntegrationFlowDefinition split(
Object service, String methodName = null, Object service, String methodName = null,
@DelegatesTo(value = SplitterEndpointSpec<MethodInvokingSplitter>, strategy = Closure.DELEGATE_FIRST) @DelegatesTo(value = SplitterEndpointSpec<MethodInvokingSplitter>, strategy = Closure.DELEGATE_FIRST)
@@ -772,7 +808,10 @@ class GroovyIntegrationFlowDefinition {
* @param endpointConfigurer the {@link Consumer} to provide integration endpoint options * @param endpointConfigurer the {@link Consumer} to provide integration endpoint options
* and for {@link MethodInvokingSplitter}. * and for {@link MethodInvokingSplitter}.
* @see org.springframework.integration.dsl.SplitterEndpointSpec * @see org.springframework.integration.dsl.SplitterEndpointSpec
* @deprecated since 6.2 in favor of {@link #splitWith(groovy.lang.Closure)}
*/ */
@Deprecated(since = '6.2', forRemoval = true)
@SuppressWarnings(['removal', 'deprecation'])
GroovyIntegrationFlowDefinition split( GroovyIntegrationFlowDefinition split(
String beanName, String methodName, String beanName, String methodName,
@DelegatesTo(value = SplitterEndpointSpec<MethodInvokingSplitter>, strategy = Closure.DELEGATE_FIRST) @DelegatesTo(value = SplitterEndpointSpec<MethodInvokingSplitter>, strategy = Closure.DELEGATE_FIRST)
@@ -791,7 +830,10 @@ class GroovyIntegrationFlowDefinition {
* @param messageProcessorSpec the splitter {@link MessageProcessorSpec}. * @param messageProcessorSpec the splitter {@link MessageProcessorSpec}.
* @param endpointConfigurer the {@link Consumer} to provide integration endpoint options * @param endpointConfigurer the {@link Consumer} to provide integration endpoint options
* and for {@link MethodInvokingSplitter}. * and for {@link MethodInvokingSplitter}.
* @deprecated since 6.2 in favor of {@link #splitWith(groovy.lang.Closure)}
*/ */
@Deprecated(since = '6.2', forRemoval = true)
@SuppressWarnings(['removal', 'deprecation'])
GroovyIntegrationFlowDefinition split( GroovyIntegrationFlowDefinition split(
MessageProcessorSpec<?> messageProcessorSpec, MessageProcessorSpec<?> messageProcessorSpec,
@DelegatesTo(value = SplitterEndpointSpec<MethodInvokingSplitter>, strategy = Closure.DELEGATE_FIRST) @DelegatesTo(value = SplitterEndpointSpec<MethodInvokingSplitter>, strategy = Closure.DELEGATE_FIRST)
@@ -811,8 +853,11 @@ class GroovyIntegrationFlowDefinition {
* Conversion to this type will be attempted, if necessary. * Conversion to this type will be attempted, if necessary.
* @param splitter the splitter {@link Function}. * @param splitter the splitter {@link Function}.
* @param endpointConfigurer the {@link Consumer} to provide integration endpoint options. * @param endpointConfigurer the {@link Consumer} to provide integration endpoint options.
* @param < P > the payload type or {@code Message.class}. * @param <P> the payload type or {@code Message.class}.
* @deprecated since 6.2 in favor of {@link #splitWith(groovy.lang.Closure)}
*/ */
@Deprecated(since = '6.2', forRemoval = true)
@SuppressWarnings(['removal', 'deprecation'])
<P> GroovyIntegrationFlowDefinition split( <P> GroovyIntegrationFlowDefinition split(
Class<P> expectedType, Function<P, ?> splitter, Class<P> expectedType, Function<P, ?> splitter,
@DelegatesTo(value = SplitterEndpointSpec<MethodInvokingSplitter>, strategy = Closure.DELEGATE_FIRST) @DelegatesTo(value = SplitterEndpointSpec<MethodInvokingSplitter>, strategy = Closure.DELEGATE_FIRST)
@@ -830,9 +875,12 @@ class GroovyIntegrationFlowDefinition {
* flow position. * flow position.
* @param splitterMessageHandlerSpec the {@link MessageHandlerSpec} to populate. * @param splitterMessageHandlerSpec the {@link MessageHandlerSpec} to populate.
* @param endpointConfigurer the {@link Consumer} to provide integration endpoint options. * @param endpointConfigurer the {@link Consumer} to provide integration endpoint options.
* @param < S > the {@link AbstractMessageSplitter} * @param <S> the {@link AbstractMessageSplitter}
* @deprecated since 6.2 in favor of {@link #splitWith(groovy.lang.Closure)}
* @see org.springframework.integration.dsl.SplitterEndpointSpec * @see org.springframework.integration.dsl.SplitterEndpointSpec
*/ */
@Deprecated(since = '6.2', forRemoval = true)
@SuppressWarnings(['removal', 'deprecation'])
<S extends AbstractMessageSplitter> GroovyIntegrationFlowDefinition split( <S extends AbstractMessageSplitter> GroovyIntegrationFlowDefinition split(
MessageHandlerSpec<?, S> splitterMessageHandlerSpec, MessageHandlerSpec<?, S> splitterMessageHandlerSpec,
@DelegatesTo(value = SplitterEndpointSpec<S>, strategy = Closure.DELEGATE_FIRST) @DelegatesTo(value = SplitterEndpointSpec<S>, strategy = Closure.DELEGATE_FIRST)
@@ -848,9 +896,12 @@ class GroovyIntegrationFlowDefinition {
* flow position. * flow position.
* @param splitter the {@link AbstractMessageSplitter} to populate. * @param splitter the {@link AbstractMessageSplitter} to populate.
* @param endpointConfigurer the {@link Consumer} to provide integration endpoint options. * @param endpointConfigurer the {@link Consumer} to provide integration endpoint options.
* @param < S > the {@link AbstractMessageSplitter} * @param <S> the {@link AbstractMessageSplitter}
* @deprecated since 6.2 in favor of {@link #splitWith(groovy.lang.Closure)}
* @see org.springframework.integration.dsl.SplitterEndpointSpec * @see org.springframework.integration.dsl.SplitterEndpointSpec
*/ */
@Deprecated(since = '6.2', forRemoval = true)
@SuppressWarnings(['removal', 'deprecation'])
<S extends AbstractMessageSplitter> GroovyIntegrationFlowDefinition split( <S extends AbstractMessageSplitter> GroovyIntegrationFlowDefinition split(
S splitter, S splitter,
@DelegatesTo(value = SplitterEndpointSpec<S>, strategy = Closure.DELEGATE_FIRST) @DelegatesTo(value = SplitterEndpointSpec<S>, strategy = Closure.DELEGATE_FIRST)

View File

@@ -269,8 +269,15 @@ class GroovyDslTests {
transform { transform {
transformer { it.toUpperCase() } transformer { it.toUpperCase() }
} }
split Message<?>, { it.payload } splitWith {
split Object, { it }, { id 'splitterEndpoint' } expectedType Message<?>
function { it.payload }
}
splitWith {
expectedType Object
id 'splitterEndpoint'
function { it }
}
resequence() resequence()
aggregate { aggregate {
id 'aggregator' id 'aggregator'

View File

@@ -89,8 +89,15 @@ functionFlow() {
transformer { it.toUpperCase() } transformer { it.toUpperCase() }
expectedType String expectedType String
} }
split Message<?>, { it.payload } splitWith {
split Object, { it }, { id 'splitterEndpoint' } expectedType Message<?>
function { it.payload }
}
splitWith {
expectedType Object
id 'splitterEndpoint'
function { it }
}
resequence() resequence()
aggregate { aggregate {
id 'aggregator' id 'aggregator'

View File

@@ -97,7 +97,10 @@ fun someFlow() =
@Bean @Bean
someFlow() { someFlow() {
integrationFlow { integrationFlow {
split Message<?>, { it.payload } splitWith {
expectedType Message<?>
function { it.payload }
}
} }
} }
---- ----

View File

@@ -229,8 +229,12 @@ fun unzipFlow(executor: Executor) =
unzipFlow(Executor executor) { unzipFlow(Executor executor) {
integrationFlow 'unzipChannel', integrationFlow 'unzipChannel',
{ {
transform new UnZipTransformer() transformWith {
split new UnZipResultSplitter() ref new UnZipTransformer()
}
splitWith {
ref new UnZipResultSplitter()
}
channel { executor 'entriesChannel', executor } channel { executor 'entriesChannel', executor }
} }
} }