Spring Integration Java DSL¶
The IntegrationFlow DSL replaces endpoint and channel beans with a fluent declaration. This page rebuilds the flow from the previous page — GET /all inbound gateway → reactive channel → WebFlux outbound gateway → GET /posts — with the DSL.
The flow definition¶
@Configuration
@EnableIntegration
@IntegrationComponentScan
public class IntegrationDslConfig {
@Bean
public IntegrationFlow inboundChannelAdapterFlow() {
return IntegrationFlow
.from(
WebFlux
.inboundGateway("/all")
.requestMapping(m -> m.methods(HttpMethod.GET))
)
.channel(c -> c.flux("outboundReactive.input"))
.get();
}
@Bean
public IntegrationFlow outboundReactive() {
return f -> f
.handle(
WebFlux
.<MultiValueMap<String, String>>outboundGateway(
m -> UriComponentsBuilder
.fromUriString("http://localhost:8080/posts")
.build()
.toUri()
)
.httpMethod(HttpMethod.GET)
.expectedResponseType(String.class)
);
}
}
Reading the DSL:
WebFlux.inboundGateway("/all")declares the HTTP entry point — equivalent to theWebFluxInboundEndpointbean from the annotation-based version, including itsRequestMapping..channel(c -> c.flux("outboundReactive.input"))bridges the gateway to the second flow through aFluxMessageChannelcreated on the fly and named after the target flow's input channel. With the DSL there is no need to declare theFluxMessageChannelbean by hand.WebFlux.outboundGateway(...)is the DSL counterpart ofWebFluxRequestExecutingMessageHandler: it executes aGET http://localhost:8080/poststhrough aWebClientand delivers the response payload, typed byexpectedResponseType, to the flow's output.
The dependency list and the application skeleton are identical to the annotation-based sample; only the configuration class changes.
Verify¶
The test is the same as the annotation-based sample — both routes return 200:
@Test
public void getAllPostsWillBeOk_viaIntegration() {
this.rest
.get()
.uri("/all")
.exchange()
.expectStatus().isOk();
}
What's next¶
The DSL scales to real pipelines: add .filter(...), .transform(...), .split(...) between the gateway and the outbound gateway, and swap the outbound target for any messaging middleware. For channel patterns that connect Integration with Redis pub/sub and Reactor Sinks, see Reactive Message Channels.
Sample¶
You can explore the complete codes in spring-reactive-sample/integration-dsl.