title |
---|
Intro to Spring Cloud Functions |
- What: Spring Cloud Function (SCF) is a project that promotes the implementation of business logic via functions
- What: Spring Cloud Function (SCF) is a project that promotes the implementation of business logic via functions
- Why: To decouple the development lifecycle of business logic from any specific runtime target so that the same code can run as a web endpoint, a stream processor, or a task
- What: Spring Cloud Function (SCF) is a project that promotes the implementation of business logic via functions
- Why: To decouple the development lifecycle of business logic from any specific runtime target so that the same code can run as a web endpoint, a stream processor, or a task
- How: By providing a uniform programming model across serverless providers, as well as the ability to run standalone (locally or in a PaaS)
SCF builds on the 3 core functional interfaces available since Java 8:
Supplier<O>
Function<I,O>
Consumer<I>
Collectively, these are referred to within SCF as "functional beans"
N/ASCF instruments Java functions with additional features to be utilised in variety of execution contexts:
- REST support: allows functions to be exposed as HTTP endpoints
- Event-driven microservices: functions can be integrated with cloud events e.g. EventBridge
- Streaming message handler: send or receive messages from a broker (such as Kafka) by leveraging integrations with the Spring Cloud Stream project
@Component
public class UpperCaseFunction implements Function<String, String> {
@Override
public String apply(String value) {
return value.toUpperCase();
}
}
@SpringBootApplication
public class SimpleFunctionAppApplication {
@Bean
public Function<String, String> uppercase() {
return value -> value.toUpperCase();
}
public static void main(String[] args) {
SpringApplication.run(SimpleFunctionAppApplication.class, args);
}
}
http://localhost:8080/swagger-ui/index.html
- In my experience, does very well to facilitate integrations allowing the developer to focus on business logic
- Enables Spring Boot features (autoconfiguration, dependency injection, metrics, etc.) on serverless providers
- SCF can be public cloud vendor agnostic
- adapters for MAG (plus others) serverless service providers exist already
- Supports function composition
- Demo Repo contains:
- SCF x2 following
@Bean
style - SCF x1 following
@Component
style - Small CDK demo stack to demonstrate necessary lambda configuration
- Some example SCF unit tests
- SCF x2 following
- Unsure if the best SCF features/practices have been applied
- Open to feedback in the form of code review, PR, written etc.