How can we achieve the equivalent of ListenableFuture
async=false with Mono<?>
or CompletableFuture
in Spring Integration 5.x?
We have a lot of reactive handlers (service activator pattern) from a common library and do not wish to rewrite them as blocking for normal GenericHandler
.
Kindly suggest.
P.S: As per documentation ListenableFuture is deprecated in Spring Integration 6.x, hence want to implement the future (Spring Integration 6.x) way. Thanks
Sample:
@Bean
public IntegrationFlow monoAsyncFalseFlow() {
// @formatter:off
return IntegrationFlows.fromSupplier(() -> "Good Morning")
.handle(monoResponseHandler(), ec -> ec.async(false))
// expect "Good Morning", however it is still a Mono<"Good Morning"> though async=false
.log(LoggingHandler.Level.INFO, m -> m.getPayload())
.get();
// @formatter:on
}
@Bean
public GenericHandler<String> monoResponseHandler() {
return (p, h) -> Mono.just(p);
}
If you do async=false
, the Mono
or CompletableFuture
is going to be as a payload of a reply message from your handler. And from here you are on your own to deal with that payload in the next step of your integration flow.
Probably, if you share some example of your scenario, we can help to determine what and how has to be done in your configuration or logic.