GH-243, GH-257 Added reactive consumer wrapper
- Added wrapper for an already reactive consumer to ensure that consumers can be consistently represented as Function<Flux, Mono> - Fixed the big that deal with inconsistent result in web environments due to inconsistent representation of the Consumers - Polished tests Resolves #243 Resolves #257
This commit is contained in:
@@ -40,7 +40,9 @@ import reactor.core.publisher.Mono;
|
||||
import org.springframework.beans.factory.ObjectProvider;
|
||||
import org.springframework.cloud.function.context.catalog.FunctionInspector;
|
||||
import org.springframework.cloud.function.context.message.MessageUtils;
|
||||
import org.springframework.cloud.function.core.FluxConsumer;
|
||||
import org.springframework.cloud.function.core.FluxWrapper;
|
||||
import org.springframework.cloud.function.core.FluxedConsumer;
|
||||
import org.springframework.cloud.function.json.JsonMapper;
|
||||
import org.springframework.cloud.function.web.util.HeaderUtils;
|
||||
import org.springframework.core.MethodParameter;
|
||||
@@ -200,7 +202,14 @@ public class RequestProcessor {
|
||||
flux = messages(wrapper, function == null ? consumer : function, flux);
|
||||
}
|
||||
Mono<ResponseEntity<?>> responseEntityMono = null;
|
||||
if (function != null) {
|
||||
|
||||
if (function instanceof FluxedConsumer || function instanceof FluxConsumer) {
|
||||
((Mono<?>) function.apply(flux)).subscribe();
|
||||
logger.debug("Handled POST with consumer");
|
||||
responseEntityMono = Mono
|
||||
.just(ResponseEntity.status(HttpStatus.ACCEPTED).build());
|
||||
}
|
||||
else {
|
||||
Flux<?> result = Flux.from(function.apply(flux));
|
||||
logger.debug("Handled POST with function");
|
||||
if (stream) {
|
||||
@@ -211,12 +220,6 @@ public class RequestProcessor {
|
||||
body == null ? null : !(body instanceof Collection), false);
|
||||
}
|
||||
}
|
||||
else if (consumer != null) {
|
||||
consumer.accept(flux);
|
||||
logger.debug("Handled POST with consumer");
|
||||
responseEntityMono = Mono
|
||||
.just(ResponseEntity.status(HttpStatus.ACCEPTED).build());
|
||||
}
|
||||
return responseEntityMono;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user