I'm trying to setup a Spring Integration flow using the DSL style flows mixed with @Bean definitions. In this example, I'm attempting to mediate an incoming REST request (restCustomerGateway) as an inbound webflux gateway. I saw that you can use .payloadExpression to pull things out of the request (in this case the id path parameter...would be intersted if there are better or more typesafe ways).
I then flow it into a webflex outbound gateway (restCustomerSource) to make a downstream call, which should then be funneled back to the inbound gateway as a response. Note, there will eventually be transformers in between to do payload transformation/etc.
Simple question is, how do I structure this so that I have access to the 'id' (the path parameter, currently hardcoded to '1' in the outbound gateway invocation)? I'm assuming this is part of the message payload that flows between the two, but how do I get a handle to it?
@Bean
public WebFluxInboundEndpoint restCustomerGateway() {
return WebFlux.inboundGateway("/rest/customers/{id}")
.requestMapping(m -> m.produces(MediaType.APPLICATION_JSON_VALUE)).payloadExpression("#pathVariables.id")
.get();
}
@Bean
public WebFluxRequestExecutingMessageHandler restCustomerSource() {
return WebFlux.outboundGateway("http://localhost:8080/customers/1").httpMethod(HttpMethod.GET)
.expectedResponseType(Customer.class)
.get();
}
@Bean
public IntegrationFlow restCustomerFlow(CustomerProcessor customerProcessor) {
return IntegrationFlows
.from(restCustomerGateway())
.handle(restCustomerSource())
.handle(customerProcessor)
.get();
}