Text of cloud.spring.io › spring-cloud-function › reference › html › spring-cloud-function.html as Styx crawled it on Nov 20, 2026. The page may have changed since. Only its words are kept, without pictures or layout, and only the first part of a long page.

Open the live page

Spring Cloud Function

Spring Cloud Function Table of Contents Introduction Getting Started Programming model Function Catalog and Flexible Function Signatures Java 8 function support Function Composition Function Routing Function Arity Kotlin Lambda support Function Component Scan Standalone Web Applications Function Mapping rules Function Filtering rules Standalone Streaming Applications Deploying a Packaged Function Supported Packaging Scenarios Functional Bean Definitions Comparing Functional with Traditional Bean Definitions Limitations of Functional Bean Declaration Testing Functional Applications Dynamic Compilation Serverless Platform Adapters AWS Lambda Microsoft Azure Google Cloud Functions (Alpha) Mark Fisher, Dave Syer, Oleg Zhurakousky, Anshul Mehra 3.1.0-SNAPSHOT Introduction Spring Cloud Function is a project with the following high-level goals: Promote the implementation of business logic via functions.

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. Support a uniform programming model across serverless providers, as well as the ability to run standalone (locally or in a PaaS). Enable Spring Boot features (auto-configuration, dependency injection, metrics) on serverless providers. It abstracts away all of the transport details and infrastructure, allowing the developer to keep all the familiar tools and processes, and focus firmly on business logic.

Here’s a complete, executable, testable Spring Boot application (implementing a simple string manipulation): @SpringBootApplication public class Application { @Bean public Function<Flux<String>, Flux<String>> uppercase() { return flux -> flux.map(value -> value.toUpperCase()); } public static void main(String[] args) { SpringApplication.run(Application.class, args); } } It’s just a Spring Boot application, so it can be built, run and tested, locally and in a CI build, the same way as any other Spring Boot application.

The Function is from java.util and Flux is a Reactive Streams Publisher from Project Reactor . The function can be accessed over HTTP or messaging. Spring Cloud Function has 4 main features: In the nutshell Spring Cloud Function provides the following features: 1. Wrappers for @Beans of type Function , Consumer and Supplier , exposing them to the outside world as either HTTP endpoints and/or message stream listeners/publishers with RabbitMQ, Kafka etc.

Choice of programming styles - reactive, imperative or hybrid. Function composition and adaptation (e.g., composing imperative functions with reactive). Support for reactive function with multiple inputs and outputs allowing merging, joining and other complex streaming operation to be handled by functions. Transparent type conversion of inputs and outputs. Packaging functions for deployments, specific to the target platform (e.g., Project Riff, AWS Lambda and more) Adapters to expose function to the outside world as HTTP endpoints etc.

Deploying a JAR file containing such an application context with an isolated classloader, so that you can pack them together in a single JVM. Compiling strings which are Java function bodies into bytecode, and then turning them into @Beans that can be wrapped as above. Adapters for AWS Lambda , Azure , Google Cloud Functions , Apache OpenWhisk and possibly other "serverless" service providers. Spring Cloud is released under the non-restrictive Apache 2.0 license.

If you would like to contribute to this section of the documentation or if you find an error, please find the source code and issue trackers in the project at github . Getting Started Build from the command line (and "install" the samples): $ ./mvnw clean install (If you like to YOLO add -DskipTests .) Run one of the samples, e.g. $ java -jar spring-cloud-function-samples/function-sample/target/*.jar This runs the app and exposes its functions over HTTP, so you can convert a string to uppercase, like this: $ curl -H "Content-Type: text/plain" localhost:8080/uppercase -d Hello HELLO You can convert multiple strings (a Flux<String> ) by separating them with new lines $ curl -H "Content-Type: text/plain" localhost:8080/uppercase -d 'Hello > World' HELLOWORLD (You can use Q J in a terminal to insert a new line in a literal string like that.) Programming model Function Catalog and Flexible Function Signatures One of the main features of Spring Cloud Function is to adapt and support a range of type signatures for user-defined functions, while providing a consistent execution model.

That’s why all user defined functions are transformed into a canonical representation by FunctionCatalog . While users don’t normally have to care about the FunctionCatalog at all, it is useful to know what kind of functions are supported in user code. It is also important to understand that Spring Cloud Function provides first class support for reactive API provided by Project Reactor allowing reactive primitives such as Mono and Flux to be used as types in user defined functions providing greater flexibility when choosing programming model for your function implementation.

Reactive programming model also enables functional support for features that would be otherwise difficult to impossible to implement using imperative programming style. For more on this please read Function Arity section. Java 8 function support Spring Cloud Function embraces and builds on top of the 3 core functional interfaces defined by Java and available to us since Java 8. Supplier<O> Function<I, O> Consumer<I> Supplier Supplier can be reactive - Supplier<Flux<T>> or imperative - Supplier<T> .

From the invocation standpoint this should make no difference to the implementor of such Supplier. However, when used within frameworks (e.g., Spring Cloud Stream ), Suppliers, especially reactive, often used to represent the source of the stream, therefore they are invoked once to get the stream (e.g., Flux) to which consumers can subscribe to. In other words such suppliers represent an equivalent of an infinite stream .

However, the same reactive suppliers can also represent finite stream(s) (e.g., result set on the polled JDBC data). In those cases such reactive suppliers must be hooked up to some polling mechanism of the underlying framework. To assist with that Spring Cloud Function provides a marker annotation org.springframework.cloud.function.context.PollableSupplier to signal that such supplier produces a finite stream and may need to be polled again.

That said, it is important to understand that Spring Cloud Function itself provides no behavior for this annotation. In addition PollableSupplier annotation exposes a splittable attribute to signal that produced stream needs to be split (see Splitter EIP ) Here is the example: @PollableSupplier(splittable = true) public Supplier<Flux<String>> someSupplier() { return () -> { String v1 = String.valueOf(System.nanoTime()); String v2 = String.valueOf(System.nanoTime()); String v3 = String.valueOf(System.nanoTime()); return Flux.just(v1, v2, v3); }; } Function Function can also be written in imperative or reactive way, yet unlike Supplier and Consumer there are no special considerations for the implementor other then understanding that when used within frameworks such as Spring Cloud Stream and others, reactive function is invoked only once to pass a reference to the stream (Flux or Mono) and imperative is invoked once per event.

Consumer Consumer is a little bit special because it has a void return type, which implies blocking, at least potentially. Most likely you will not need to write Consumer<Flux<?>> , but if you do need to do that, remember to subscribe to the input flux. Function Composition Function Composition is a feature that allows one to compose several functions into one. The core support is based on function composition feature available with Function.andThen(..) support available since Java 8.

However on top of it, we provide few

The rest of this page is on the live site.