added FunctionProxyApplicationListener
added support for lambda compiling Supplier and Consumer proxies
This commit is contained in:
@@ -25,12 +25,6 @@
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<!-- TODO: this shouldn't be needed (bug in thin launcher) -->
|
||||
<groupId>io.projectreactor</groupId>
|
||||
<artifactId>reactor-core</artifactId>
|
||||
<version>${reactor.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-function-web</artifactId>
|
||||
@@ -41,11 +35,6 @@
|
||||
<artifactId>spring-cloud-function-compiler</artifactId>
|
||||
<version>${spring-cloud-function.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-configuration-processor</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
||||
@@ -16,54 +16,13 @@
|
||||
|
||||
package com.example;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.cloud.function.compiler.FunctionCompiler;
|
||||
import org.springframework.cloud.function.compiler.proxy.LambdaCompilingFunction;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.core.io.ByteArrayResource;
|
||||
|
||||
import reactor.core.publisher.Flux;
|
||||
|
||||
@SpringBootApplication
|
||||
@EnableConfigurationProperties(FunctionProperties.class)
|
||||
public class SampleApplication {
|
||||
|
||||
@Autowired
|
||||
private FunctionProperties properties;
|
||||
|
||||
@Bean
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
public Function<Flux<String>, Flux<String>> function(FunctionCompiler<?, ?> compiler) {
|
||||
ByteArrayResource resource = new ByteArrayResource(properties.getLambda().getBytes());
|
||||
return new LambdaCompilingFunction(resource, compiler);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public FunctionCompiler<?, ?> compiler() {
|
||||
return new FunctionCompiler<>();
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
SpringApplication.run(SampleApplication.class, args);
|
||||
}
|
||||
}
|
||||
|
||||
@ConfigurationProperties("function")
|
||||
class FunctionProperties {
|
||||
|
||||
private String lambda;
|
||||
|
||||
public String getLambda() {
|
||||
return lambda;
|
||||
}
|
||||
|
||||
public void setLambda(String lambda) {
|
||||
this.lambda = lambda;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT,
|
||||
properties = "function.lambda=f->f.map(s->s.toString().toLowerCase())")
|
||||
properties = "spring.cloud.function.proxy.test.lambda=f->f.map(s->s+\"!!!\")")
|
||||
public class SampleApplicationTests {
|
||||
|
||||
@LocalServerPort
|
||||
@@ -41,8 +41,8 @@ public class SampleApplicationTests {
|
||||
@Test
|
||||
public void lowercase() {
|
||||
assertThat(new TestRestTemplate().postForObject(
|
||||
"http://localhost:" + port + "/function", "{\"VALUE\":\"FOO\"}",
|
||||
String.class)).isEqualTo("{\"value\":\"foo\"}");
|
||||
"http://localhost:" + port + "/test", "it works",
|
||||
String.class)).isEqualTo("it works!!!");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user