diff --git a/spring-integration-groovy/src/main/groovy/org/springframework/integration/groovy/dsl/GroovyIntegrationFlowDefinition.groovy b/spring-integration-groovy/src/main/groovy/org/springframework/integration/groovy/dsl/GroovyIntegrationFlowDefinition.groovy index fb113a02677..3dff2470d30 100644 --- a/spring-integration-groovy/src/main/groovy/org/springframework/integration/groovy/dsl/GroovyIntegrationFlowDefinition.groovy +++ b/spring-integration-groovy/src/main/groovy/org/springframework/integration/groovy/dsl/GroovyIntegrationFlowDefinition.groovy @@ -103,6 +103,18 @@ class GroovyIntegrationFlowDefinition { this } + /** + * Populate a {@link org.springframework.integration.channel.NullChannel} instance + * at the current {@link IntegrationFlow} chain position. + * The nullChannel acts like "/dev/null". + * @since 7.0.1 + * @see org.springframework.integration.channel.NullChannel + */ + GroovyIntegrationFlowDefinition nullChannel() { + this.delegate.nullChannel() + this + } + /** * Populate a {@link org.springframework.integration.dsl.support.MessageChannelReference} instance * at the current {@link IntegrationFlow} chain position. diff --git a/spring-integration-groovy/src/test/groovy/org/springframework/integration/groovy/dsl/test/GroovyDslTests.groovy b/spring-integration-groovy/src/test/groovy/org/springframework/integration/groovy/dsl/test/GroovyDslTests.groovy index 8940e71eb28..b6a0ede3ad3 100644 --- a/spring-integration-groovy/src/test/groovy/org/springframework/integration/groovy/dsl/test/GroovyDslTests.groovy +++ b/spring-integration-groovy/src/test/groovy/org/springframework/integration/groovy/dsl/test/GroovyDslTests.groovy @@ -220,6 +220,35 @@ class GroovyDslTests { assert groovyTestService.result.get() == 'TEST' } + @Autowired + @Qualifier('nullChannelFlow.input') + private MessageChannel nullChannelFlowInput + + @Autowired + private MessageChannel nullCheckWireTapChannel + + + @Test + void 'nullChannelFlow discards messages'() { + nullChannelFlowInput.send MessageBuilder.withPayload('test').build() + def tappedMessage = nullCheckWireTapChannel.receive(1000) + + //verify that a message was sent and assume nullChannel discarded it. + assert tappedMessage?.payload == 'test' + } + + @Autowired + @Qualifier('nullChannelWithTransformFlow.input') + private MessageChannel nullChannelWithTransformFlowInput + + @Test + void 'nullChannel can be used after transform in a flow'() { + nullChannelWithTransformFlowInput.send MessageBuilder.withPayload('test').build() + def tappedMessage = nullCheckWireTapChannel.receive(1000) + //verify that a message was sent, transformed and assume nullChannel discarded it. + assert tappedMessage?.payload == 'TEST' + } + @Configuration(proxyBeanMethods = false) @EnableIntegration static class Config { @@ -361,6 +390,30 @@ class GroovyDslTests { } + @Bean + nullChannelFlow(@Qualifier('nullCheckWireTapChannel') MessageChannel nullCheckWireTapChannel) { + integrationFlow { + wireTap(nullCheckWireTapChannel) + nullChannel() + } + } + + @Bean + nullChannelWithTransformFlow(@Qualifier('nullCheckWireTapChannel') MessageChannel nullCheckWireTapChannel) { + integrationFlow { + transform { + transformer { it.toUpperCase() } + } + wireTap(nullCheckWireTapChannel) + nullChannel() + } + } + + @Bean + MessageChannel nullCheckWireTapChannel() { + new QueueChannel() + } + } @CompileStatic