diff --git a/multi/multi__function_catalog_and_flexible_function_signatures.html b/multi/multi__function_catalog_and_flexible_function_signatures.html index 97987f529..f0404320b 100644 --- a/multi/multi__function_catalog_and_flexible_function_signatures.html +++ b/multi/multi__function_catalog_and_flexible_function_signatures.html @@ -1,12 +1,13 @@ - 4. Function Catalog and Flexible Function Signatures

4. 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. So -users can supply a bean of type Function<String,String>, for -instance, and the FunctionCatalog will wrap it into a -Function<Flux<String>,Flux<String>>. Users don’t normally have to -care about the FunctionCatalog at all, but it is useful to know what -kind of functions are supported in user code.

Generally speaking users can expect that if they write a function for + 4. Function Catalog and Flexible Function Signatures

4. 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, using primitives +defined by the Project Reactor (i.e., Flux<T> and Mono<T>). +Users can supply a bean of type Function<String,String>, for instance, and the FunctionCatalog will wrap it into a +Function<Flux<String>,Flux<String>>.

Using Reactor based primitives not only helps with the canonical representation of user defined functions, but it also +facilitates a more robust and flexible(reactive) execution model.

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.

4.1 Java 8 function support

Generally speaking users can expect that if they write a function for a plain old Java type (or primitive wrapper), then the function catalog will wrap it to a Flux of the same type. If the user writes a function using Message (from spring-messaging) it will receive and @@ -17,10 +18,21 @@ need to write Consumer<Flux<?>>, but if remember to subscribe to the input flux. If you declare a Consumer of a non publisher type (which is normal), it will be converted to a function that returns a publisher, so that it can be subscribed to in -a controlled way.

A function catalog can contain a Supplier and a Function (or -Consumer) with the same name (like a GET and a POST to the same -resource). It can even contain a Consumer<Flux<>> with the same name -as a Function, but it cannot contain a Consumer<T> and a -Function<T,S> with the same name when T is not a Publisher -because the consumer would be converted to a Function and only one -of them can be registered.

\ No newline at end of file +a controlled way.

4.2 Kotlin Lambda support

We also provide support for Kotlin lambdas (since v2.0). +Consider the following:

@Bean
+open fun kotlinSupplier(): () -> String {
+    return  { "Hello from Kotlin" }
+}
+
+@Bean
+open fun kotlinFunction(): (String) -> String {
+    return  { it.toUpperCase() }
+}
+
+@Bean
+open fun kotlinConsumer(): (String) -> Unit {
+    return  { println(it) }
+}

The above represents Kotlin lambdas configured as Spring beans. The signature of each maps to a Java equivalent of +Supplier, Function and Consumer, and thus supported/recognized signatures by the framework. +While mechanics of Kotlin-to-Java mapping are outside of the scope of this documentation, it is important to understand that the +same rules for signature transformation outlined in "Java 8 function support" section are applied here as well.

\ No newline at end of file diff --git a/multi/multi_spring-cloud-function.html b/multi/multi_spring-cloud-function.html index 0a9cb8cb5..1835d0b32 100644 --- a/multi/multi_spring-cloud-function.html +++ b/multi/multi_spring-cloud-function.html @@ -1,3 +1,3 @@ - Spring Cloud Function

Spring Cloud Function


Table of Contents

1. Introduction
2. Getting Started
3. Building and Running a Function
4. Function Catalog and Flexible Function Signatures
5. Standalone Web Applications
6. Standalone Streaming Applications
7. Deploying a Packaged Function
8. Dynamic Compilation
9. Serverless Platform Adapters
9.1. AWS Lambda
9.1.1. Introduction
9.1.2. Notes on JAR Layout
9.1.3. Upload
9.1.4. Platfom Specific Features
HTTP and API Gateway
9.2. Azure Functions
9.2.1. Notes on JAR Layout
9.2.2. JSON Configuration
9.2.3. Build
9.2.4. Running the sample
9.3. Apache Openwhisk
9.3.1. Quick Start
\ No newline at end of file + Spring Cloud Function

Spring Cloud Function


Table of Contents

1. Introduction
2. Getting Started
3. Building and Running a Function
4. Function Catalog and Flexible Function Signatures
4.1. Java 8 function support
4.2. Kotlin Lambda support
5. Standalone Web Applications
6. Standalone Streaming Applications
7. Deploying a Packaged Function
8. Dynamic Compilation
9. Serverless Platform Adapters
9.1. AWS Lambda
9.1.1. Introduction
9.1.2. Notes on JAR Layout
9.1.3. Upload
9.1.4. Platfom Specific Features
HTTP and API Gateway
9.2. Azure Functions
9.2.1. Notes on JAR Layout
9.2.2. JSON Configuration
9.2.3. Build
9.2.4. Running the sample
9.3. Apache Openwhisk
9.3.1. Quick Start
\ No newline at end of file diff --git a/single/spring-cloud-function.html b/single/spring-cloud-function.html index e9dc133a9..274f0cce0 100644 --- a/single/spring-cloud-function.html +++ b/single/spring-cloud-function.html @@ -1,6 +1,6 @@ - Spring Cloud Function

Spring Cloud Function


Table of Contents

1. Introduction
2. Getting Started
3. Building and Running a Function
4. Function Catalog and Flexible Function Signatures
5. Standalone Web Applications
6. Standalone Streaming Applications
7. Deploying a Packaged Function
8. Dynamic Compilation
9. Serverless Platform Adapters
9.1. AWS Lambda
9.1.1. Introduction
9.1.2. Notes on JAR Layout
9.1.3. Upload
9.1.4. Platfom Specific Features
HTTP and API Gateway
9.2. Azure Functions
9.2.1. Notes on JAR Layout
9.2.2. JSON Configuration
9.2.3. Build
9.2.4. Running the sample
9.3. Apache Openwhisk
9.3.1. Quick Start

Mark Fisher, Dave Syer, Oleg Zhurakousky

1. 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 + Spring Cloud Function

Spring Cloud Function


Mark Fisher, Dave Syer, Oleg Zhurakousky

1. 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
@@ -46,13 +46,14 @@ POJO) JSON. TBD: support for Flux<Message<Pojo>&g
 Pojo types (Fluxes implied and implemented by the framework).

Functions can be grouped together in a single application, or deployed one-per-jar. It’s up to the developer to choose. An app with multiple functions can be deployed multiple times in different "personalities", -exposing different functions over different physical transports.

4. 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. So -users can supply a bean of type Function<String,String>, for -instance, and the FunctionCatalog will wrap it into a -Function<Flux<String>,Flux<String>>. Users don’t normally have to -care about the FunctionCatalog at all, but it is useful to know what -kind of functions are supported in user code.

Generally speaking users can expect that if they write a function for +exposing different functions over different physical transports.

4. 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, using primitives +defined by the Project Reactor (i.e., Flux<T> and Mono<T>). +Users can supply a bean of type Function<String,String>, for instance, and the FunctionCatalog will wrap it into a +Function<Flux<String>,Flux<String>>.

Using Reactor based primitives not only helps with the canonical representation of user defined functions, but it also +facilitates a more robust and flexible(reactive) execution model.

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.

4.1 Java 8 function support

Generally speaking users can expect that if they write a function for a plain old Java type (or primitive wrapper), then the function catalog will wrap it to a Flux of the same type. If the user writes a function using Message (from spring-messaging) it will receive and @@ -63,13 +64,24 @@ need to write Consumer<Flux<?>>, but if remember to subscribe to the input flux. If you declare a Consumer of a non publisher type (which is normal), it will be converted to a function that returns a publisher, so that it can be subscribed to in -a controlled way.

A function catalog can contain a Supplier and a Function (or -Consumer) with the same name (like a GET and a POST to the same -resource). It can even contain a Consumer<Flux<>> with the same name -as a Function, but it cannot contain a Consumer<T> and a -Function<T,S> with the same name when T is not a Publisher -because the consumer would be converted to a Function and only one -of them can be registered.

5. Standalone Web Applications

The spring-cloud-function-web module has autoconfiguration that +a controlled way.

4.2 Kotlin Lambda support

We also provide support for Kotlin lambdas (since v2.0). +Consider the following:

@Bean
+open fun kotlinSupplier(): () -> String {
+    return  { "Hello from Kotlin" }
+}
+
+@Bean
+open fun kotlinFunction(): (String) -> String {
+    return  { it.toUpperCase() }
+}
+
+@Bean
+open fun kotlinConsumer(): (String) -> Unit {
+    return  { println(it) }
+}

The above represents Kotlin lambdas configured as Spring beans. The signature of each maps to a Java equivalent of +Supplier, Function and Consumer, and thus supported/recognized signatures by the framework. +While mechanics of Kotlin-to-Java mapping are outside of the scope of this documentation, it is important to understand that the +same rules for signature transformation outlined in "Java 8 function support" section are applied here as well.

5. Standalone Web Applications

The spring-cloud-function-web module has autoconfiguration that activates when it is included in a Spring Boot web application (with MVC support). There is also a spring-cloud-starter-function-web to collect all the optional dependnecies in case you just want a simple diff --git a/spring-cloud-function.xml b/spring-cloud-function.xml index 01c34dd4a..24a8d275d 100644 --- a/spring-cloud-function.xml +++ b/spring-cloud-function.xml @@ -119,13 +119,18 @@ exposing different functions over different physical transports. 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. So -users can supply a bean of type Function<String,String>, for -instance, and the FunctionCatalog will wrap it into a -Function<Flux<String>,Flux<String>>. Users don’t normally have to -care about the FunctionCatalog at all, but it is useful to know what +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, using primitives +defined by the Project Reactor (i.e., Flux<T> and Mono<T>). +Users can supply a bean of type Function<String,String>, for instance, and the FunctionCatalog will wrap it into a +Function<Flux<String>,Flux<String>>. +Using Reactor based primitives not only helps with the canonical representation of user defined functions, but it also +facilitates a more robust and flexible(reactive) execution model. +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. +

+Java 8 function support Generally speaking users can expect that if they write a function for a plain old Java type (or primitive wrapper), then the function catalog will wrap it to a Flux of the same type. If the user writes @@ -195,13 +200,30 @@ remember to subscribe to the input flux. If you declare a Consumer -A function catalog can contain a Supplier and a Function (or -Consumer) with the same name (like a GET and a POST to the same -resource). It can even contain a Consumer<Flux<>> with the same name -as a Function, but it cannot contain a Consumer<T> and a -Function<T,S> with the same name when T is not a Publisher -because the consumer would be converted to a Function and only one -of them can be registered. +
+
+Kotlin Lambda support +We also provide support for Kotlin lambdas (since v2.0). +Consider the following: +@Bean +open fun kotlinSupplier(): () -> String { + return { "Hello from Kotlin" } +} + +@Bean +open fun kotlinFunction(): (String) -> String { + return { it.toUpperCase() } +} + +@Bean +open fun kotlinConsumer(): (String) -> Unit { + return { println(it) } +} +The above represents Kotlin lambdas configured as Spring beans. The signature of each maps to a Java equivalent of +Supplier, Function and Consumer, and thus supported/recognized signatures by the framework. +While mechanics of Kotlin-to-Java mapping are outside of the scope of this documentation, it is important to understand that the +same rules for signature transformation outlined in "Java 8 function support" section are applied here as well. +
Standalone Web Applications