updated SCF azure sample
This commit is contained in:
@@ -35,6 +35,11 @@ public class HttpTriggerDemoApplication {
|
||||
return payload -> payload.toUpperCase();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Function<String, String> reverse() {
|
||||
return payload -> new StringBuilder(payload).reverse().toString();
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(HttpTriggerDemoApplication.class, args);
|
||||
}
|
||||
|
||||
@@ -27,23 +27,48 @@ import com.microsoft.azure.functions.annotation.FunctionName;
|
||||
import com.microsoft.azure.functions.annotation.HttpTrigger;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cloud.function.context.FunctionCatalog;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class MyAzureFunction {
|
||||
|
||||
/**
|
||||
* Plain Spring bean (not Spring Cloud Functions!)
|
||||
*/
|
||||
@Autowired
|
||||
private Function<String, String> echo;
|
||||
|
||||
/**
|
||||
* Plain Spring bean (not Spring Cloud Functions!)
|
||||
*/
|
||||
@Autowired
|
||||
private Function<String, String> uppercase;
|
||||
|
||||
@FunctionName("ditest")
|
||||
public String execute(
|
||||
/**
|
||||
* The FunctionCatalog leverages the Spring Cloud Function framework.
|
||||
*/
|
||||
@Autowired
|
||||
private FunctionCatalog functionCatalog;
|
||||
|
||||
@FunctionName("bean")
|
||||
public String plainBeans(
|
||||
@HttpTrigger(name = "req", methods = { HttpMethod.GET,
|
||||
HttpMethod.POST }, authLevel = AuthorizationLevel.ANONYMOUS) HttpRequestMessage<Optional<String>> request,
|
||||
ExecutionContext context) {
|
||||
|
||||
return echo.andThen(uppercase).apply(request.getBody().get());
|
||||
}
|
||||
|
||||
@FunctionName("scf")
|
||||
public String springCloudFunction(
|
||||
@HttpTrigger(name = "req", methods = { HttpMethod.GET,
|
||||
HttpMethod.POST }, authLevel = AuthorizationLevel.ANONYMOUS) HttpRequestMessage<Optional<String>> request,
|
||||
ExecutionContext context) {
|
||||
|
||||
// Use SCF composition. Composed functions are not just spring beans but SCF such.
|
||||
Function composed = this.functionCatalog.lookup("echo|reverse|uppercase");
|
||||
|
||||
return (String) composed.apply(request.getBody().get());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user