GH-2300: Add Flux support in WebFluxRequestExecMH

Fixes: spring-projects/spring-integration#2300

To allow to consume a streaming HTTP response downstream expose
`replyToFlux` option on the `WebFluxRequestExecutingMessageHandler`.
This way the body of the HTTP response can be converted now to the
`Flux` for subsequent output message.
The option is `false` by default; can be changed to `true` in the `5.1`
This commit is contained in:
Artem Bilan
2017-12-14 14:21:01 -05:00
committed by Gary Russell
parent 21bf69b7f8
commit bd872846fb
7 changed files with 144 additions and 28 deletions

View File

@@ -95,10 +95,13 @@ You can configure a `WebClient` instance to use:
</bean>
----
The `WebClient` `exchange()` operation returns a `Mono<ClientResponse>` which is mapped to the `AbstractIntegrationMessageBuilder` reactive support (using `Mono.map()`) as the output from the `WebFluxRequestExecutingMessageHandler`.
The `WebClient` `exchange()` operation returns a `Mono<ClientResponse>` which is mapped (using several `Mono.map()` steps) to an `AbstractIntegrationMessageBuilder` as the output from the `WebFluxRequestExecutingMessageHandler`.
Together with the `ReactiveChannel` as an `outputChannel`, the `Mono<ClientResponse>` evaluation is deferred until a downstream subscription is made.
Otherwise, it is treated as an `async` mode and the `Mono` response is adapted to an `SettableListenableFuture` for an asynchronous reply from the `WebFluxRequestExecutingMessageHandler`.
The target payload of the output message depends on the `WebFluxRequestExecutingMessageHandler` configuration.
The `setExpectedResponseType(Class<?>)` or `setExpectedResponseTypeExpression(Expression)` identifies the target type of the response body element conversion.
If `replyToFlux` is set to `true`, the response body is converted to a `Flux` with the provided `expectedResponseType` for each element and this `Flux` is sent as the payload downstream.
A <<splitter,splitter>> afterwards can be used to iterate over this `Flux` in a reactive manner.
Also see <<http-outbound>> for more possible configuration options.
@@ -237,4 +240,4 @@ public IntegrationFlow outboundReactive() {
=== WebFlux Header Mappings
Since WebFlux components are fully based on the HTTP protocol there is no difference in the HTTP headers mapping.
See <<http-header-mapping>> for more possible options and components to use for mapping headers.
See <<http-header-mapping>> for more possible options and components to use for mapping headers.