Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,17 @@ 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".
* @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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,50 @@ class GroovyDslTests {
assert groovyTestService.result.get() == 'TEST'
}

@Autowired
@Qualifier('nullChannelFlow.input')
private MessageChannel nullChannelFlowInput

@Test
void 'nullChannelFlow discards messages'() {
def wireTapChannel = new QueueChannel()
def testFlow = integrationFlow {
wireTap(wireTapChannel)
nullChannel()
}
def registration = this.integrationFlowContext.registration(testFlow).register()
registration.inputChannel.send(new GenericMessage<Object>('test'))
def tappedMessage = wireTapChannel.receive(1000)
registration.destroy()

assert tappedMessage?.payload == 'test' //verify that a message was sent and assume nullChannel discarded it.

}

@Autowired
@Qualifier('nullChannelWithTransformFlow.input')
private MessageChannel nullChannelWithTransformFlowInput

@Test
void 'nullChannel can be used after transform in a flow'() {
def wireTapChannel = new QueueChannel()
def testFlow = integrationFlow {
transform {
transformer { it.toUpperCase() }
}
wireTap(wireTapChannel)
nullChannel()
}
def registration = this.integrationFlowContext.registration(testFlow).register()
registration.inputChannel.send(new GenericMessage<Object>('test'))
def tappedMessage = wireTapChannel.receive(1000)
registration.destroy()

//verify that a message was sent, transformed and assume nullChannel discarded it.
assert tappedMessage?.payload == 'TEST'

}

@Configuration(proxyBeanMethods = false)
@EnableIntegration
static class Config {
Expand Down Expand Up @@ -361,6 +405,27 @@ class GroovyDslTests {

}

@Bean
nullChannelFlow() {
integrationFlow {
{
log LoggingHandler.Level.WARN, 'test.category'
}
nullChannel()
}

}

@Bean
nullChannelWithTransformFlow() {
integrationFlow {
transform {
transformer { it.toUpperCase() }
}
nullChannel()
}
}

}

@CompileStatic
Expand Down