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:
@@ -35,6 +35,7 @@ import org.springframework.cloud.function.core.FluxConsumer;
|
||||
import org.springframework.cloud.function.core.FluxFunction;
|
||||
import org.springframework.cloud.function.core.FluxSupplier;
|
||||
import org.springframework.cloud.function.core.FluxToMonoFunction;
|
||||
import org.springframework.cloud.function.core.FluxedConsumer;
|
||||
import org.springframework.cloud.function.core.MonoToFluxFunction;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
@@ -164,6 +165,11 @@ public class FunctionRegistration<T> implements BeanNameAware {
|
||||
target = (S) new FluxConsumer((Consumer<?>) target);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (target instanceof Consumer) {
|
||||
target = (S) new FluxedConsumer((Consumer<?>) target);
|
||||
}
|
||||
}
|
||||
|
||||
if (Mono.class.isAssignableFrom(type.getOutputWrapper())) {
|
||||
target = (S) new FluxToMonoFunction((Function) target);
|
||||
|
||||
@@ -58,7 +58,6 @@ import org.springframework.cloud.function.context.FunctionCatalog;
|
||||
import org.springframework.cloud.function.context.FunctionRegistration;
|
||||
import org.springframework.cloud.function.context.FunctionRegistry;
|
||||
import org.springframework.cloud.function.context.FunctionType;
|
||||
import org.springframework.cloud.function.context.catalog.FunctionInspector;
|
||||
import org.springframework.cloud.function.context.catalog.FunctionRegistrationEvent;
|
||||
import org.springframework.cloud.function.context.catalog.FunctionUnregistrationEvent;
|
||||
import org.springframework.cloud.function.core.FluxConsumer;
|
||||
@@ -562,22 +561,22 @@ public class ContextFunctionCatalogAutoConfiguration {
|
||||
|
||||
}
|
||||
|
||||
protected class BeanFactoryFunctionInspector implements FunctionInspector {
|
||||
|
||||
private ContextFunctionRegistry processor;
|
||||
|
||||
public BeanFactoryFunctionInspector(ContextFunctionRegistry processor) {
|
||||
this.processor = processor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FunctionRegistration<?> getRegistration(Object function) {
|
||||
FunctionRegistration<?> registration = this.processor
|
||||
.getRegistration(function);
|
||||
return registration;
|
||||
}
|
||||
|
||||
}
|
||||
// protected class BeanFactoryFunctionInspector implements FunctionInspector {
|
||||
//
|
||||
// private ContextFunctionRegistry processor;
|
||||
//
|
||||
// public BeanFactoryFunctionInspector(ContextFunctionRegistry processor) {
|
||||
// this.processor = processor;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public FunctionRegistration<?> getRegistration(Object function) {
|
||||
// FunctionRegistration<?> registration = this.processor
|
||||
// .getRegistration(function);
|
||||
// return registration;
|
||||
// }
|
||||
//
|
||||
// }
|
||||
|
||||
@Configuration
|
||||
@ConditionalOnClass(Gson.class)
|
||||
|
||||
@@ -560,10 +560,10 @@ public class ContextFunctionCatalogAutoConfigurationTests {
|
||||
"spring.cloud.function.compile.foos.lambda=f -> f.subscribe("
|
||||
+ getClass().getName() + "::set)",
|
||||
"spring.cloud.function.compile.foos.type=consumer");
|
||||
assertThat((Consumer<?>) this.catalog.lookup(Consumer.class, "foos"))
|
||||
.isInstanceOf(Consumer.class);
|
||||
assertThat((Function<?, ?>) this.catalog.lookup(Function.class, "foos"))
|
||||
.isInstanceOf(Function.class);
|
||||
assertThat(this.inspector
|
||||
.getInputWrapper(this.catalog.lookup(Consumer.class, "foos")))
|
||||
.getInputWrapper(this.catalog.lookup(Function.class, "foos")))
|
||||
.isEqualTo(Flux.class);
|
||||
@SuppressWarnings("unchecked")
|
||||
Consumer<Flux<String>> consumer = (Consumer<Flux<String>>) this.context
|
||||
|
||||
Reference in New Issue
Block a user