GH-256, Add AWS support for Consumer's and Supplier's

Added support for Consumer and Supplier functions when executing within AWS Lambda.

It appears that this was previously supported but was removed in 083d5e for some reason.

Improve Consumer support for AWS API Gateway

Consumer type functions, by definition, do not return anything; i.e. they do not have a response.  However when executing within a Lambda + API Gateway environment, the Lambda must still return a 200-level status response to signal the API Gateway that the function executed succesfully.   I added the logic for this.

Improve Supplier support for AWS API Gateway

Supplier functions, by defnition, do not take input; in the case of API Gateway calls this type of execution passes a null body, which fails to deserialize and throws an exception.  I added logic that skips the deserialization of the body in the case it is a Supplier.
This commit is contained in:
Semyon Fishman
2019-02-13 13:05:31 -05:00
committed by Oleg Zhurakousky
parent 94106dba48
commit 8c4c1aefde
4 changed files with 130 additions and 18 deletions

View File

@@ -18,6 +18,7 @@ package org.springframework.cloud.function.adapter.aws;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import org.junit.After;
@@ -102,6 +103,14 @@ public class SpringFunctionInitializerTests {
assertThat(result.toStream().collect(Collectors.toList())).isEmpty();
}
@Test
public void supplierCatalog() {
initializer = new SpringFunctionInitializer(SupplierConfig.class);
initializer.initialize();
Flux<?> result = Flux.from(initializer.apply(Flux.empty()));
assertThat(result.blockFirst()).isInstanceOf(Bar.class);
}
@Configuration
protected static class FluxFunctionConfig {
@@ -161,6 +170,15 @@ public class SpringFunctionInitializerTests {
}
@Configuration
@Import(ContextFunctionCatalogAutoConfiguration.class)
protected static class SupplierConfig {
@Bean
public Supplier<Bar> supplier() {
return () -> new Bar();
}
}
@Configuration
@Import(ContextFunctionCatalogAutoConfiguration.class)
protected static class ConsumerConfig {