Sync docs from master to gh-pages
This commit is contained in:
@@ -1,12 +1,13 @@
|
||||
<html><head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
||||
<title>4. Function Catalog and Flexible Function Signatures</title><link rel="stylesheet" type="text/css" href="css/manual-multipage.css"><meta name="generator" content="DocBook XSL Stylesheets V1.78.1"><link rel="home" href="multi_spring-cloud-function.html" title="Spring Cloud Function"><link rel="up" href="multi_spring-cloud-function.html" title="Spring Cloud Function"><link rel="prev" href="multi__building_and_running_a_function.html" title="3. Building and Running a Function"><link rel="next" href="multi__standalone_web_applications.html" title="5. Standalone Web Applications"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">4. Function Catalog and Flexible Function Signatures</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="multi__building_and_running_a_function.html">Prev</a> </td><th width="60%" align="center"> </th><td width="20%" align="right"> <a accesskey="n" href="multi__standalone_web_applications.html">Next</a></td></tr></table><hr></div><div class="chapter"><div class="titlepage"><div><div><h1 class="title"><a name="_function_catalog_and_flexible_function_signatures" href="#_function_catalog_and_flexible_function_signatures"></a>4. Function Catalog and Flexible Function Signatures</h1></div></div></div><p>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 <code class="literal">Function<String,String></code>, for
|
||||
instance, and the <code class="literal">FunctionCatalog</code> will wrap it into a
|
||||
<code class="literal">Function<Flux<String>,Flux<String>></code>. Users don’t normally have to
|
||||
care about the <code class="literal">FunctionCatalog</code> at all, but it is useful to know what
|
||||
kind of functions are supported in user code.</p><p>Generally speaking users can expect that if they write a function for
|
||||
<title>4. Function Catalog and Flexible Function Signatures</title><link rel="stylesheet" type="text/css" href="css/manual-multipage.css"><meta name="generator" content="DocBook XSL Stylesheets V1.78.1"><link rel="home" href="multi_spring-cloud-function.html" title="Spring Cloud Function"><link rel="up" href="multi_spring-cloud-function.html" title="Spring Cloud Function"><link rel="prev" href="multi__building_and_running_a_function.html" title="3. Building and Running a Function"><link rel="next" href="multi__standalone_web_applications.html" title="5. Standalone Web Applications"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">4. Function Catalog and Flexible Function Signatures</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="multi__building_and_running_a_function.html">Prev</a> </td><th width="60%" align="center"> </th><td width="20%" align="right"> <a accesskey="n" href="multi__standalone_web_applications.html">Next</a></td></tr></table><hr></div><div class="chapter"><div class="titlepage"><div><div><h1 class="title"><a name="_function_catalog_and_flexible_function_signatures" href="#_function_catalog_and_flexible_function_signatures"></a>4. Function Catalog and Flexible Function Signatures</h1></div></div></div><p>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 <code class="literal">FunctionCatalog</code>, using primitives
|
||||
defined by the <a class="link" href="https://projectreactor.io/" target="_top">Project Reactor</a> (i.e., <code class="literal">Flux<T></code> and <code class="literal">Mono<T></code>).
|
||||
Users can supply a bean of type <code class="literal">Function<String,String></code>, for instance, and the <code class="literal">FunctionCatalog</code> will wrap it into a
|
||||
<code class="literal">Function<Flux<String>,Flux<String>></code>.</p><p>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.</p><p>While users don’t normally have to care about the <code class="literal">FunctionCatalog</code> at all, it is useful to know what
|
||||
kind of functions are supported in user code.</p><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="_java_8_function_support" href="#_java_8_function_support"></a>4.1 Java 8 function support</h2></div></div></div><p>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 <code class="literal">Flux</code> of the same type. If the user writes
|
||||
a function using <code class="literal">Message</code> (from spring-messaging) it will receive and
|
||||
@@ -17,10 +18,21 @@ need to write <code class="literal">Consumer<Flux<?>></code>, but if
|
||||
remember to subscribe to the input flux. If you declare a <code class="literal">Consumer</code>
|
||||
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.</p><p>A function catalog can contain a <code class="literal">Supplier</code> and a <code class="literal">Function</code> (or
|
||||
<code class="literal">Consumer</code>) with the same name (like a GET and a POST to the same
|
||||
resource). It can even contain a <code class="literal">Consumer<Flux<>></code> with the same name
|
||||
as a <code class="literal">Function</code>, but it cannot contain a <code class="literal">Consumer<T></code> and a
|
||||
<code class="literal">Function<T,S></code> with the same name when <code class="literal">T</code> is not a <code class="literal">Publisher</code>
|
||||
because the consumer would be converted to a <code class="literal">Function</code> and only one
|
||||
of them can be registered.</p></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="multi__building_and_running_a_function.html">Prev</a> </td><td width="20%" align="center"> </td><td width="40%" align="right"> <a accesskey="n" href="multi__standalone_web_applications.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">3. Building and Running a Function </td><td width="20%" align="center"><a accesskey="h" href="multi_spring-cloud-function.html">Home</a></td><td width="40%" align="right" valign="top"> 5. Standalone Web Applications</td></tr></table></div></body></html>
|
||||
a controlled way.</p></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="_kotlin_lambda_support" href="#_kotlin_lambda_support"></a>4.2 Kotlin Lambda support</h2></div></div></div><p>We also provide support for Kotlin lambdas (since v2.0).
|
||||
Consider the following:</p><pre class="programlisting"><em><span class="hl-annotation" style="color: gray">@Bean</span></em>
|
||||
open fun kotlinSupplier(): () -> String {
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">return</span> { <span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"Hello from Kotlin"</span> }
|
||||
}
|
||||
|
||||
<em><span class="hl-annotation" style="color: gray">@Bean</span></em>
|
||||
open fun kotlinFunction(): (String) -> String {
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">return</span> { it.toUpperCase() }
|
||||
}
|
||||
|
||||
<em><span class="hl-annotation" style="color: gray">@Bean</span></em>
|
||||
open fun kotlinConsumer(): (String) -> Unit {
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">return</span> { println(it) }
|
||||
}</pre><p>The above represents Kotlin lambdas configured as Spring beans. The signature of each maps to a Java equivalent of
|
||||
<code class="literal">Supplier</code>, <code class="literal">Function</code> and <code class="literal">Consumer</code>, 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.</p></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="multi__building_and_running_a_function.html">Prev</a> </td><td width="20%" align="center"> </td><td width="40%" align="right"> <a accesskey="n" href="multi__standalone_web_applications.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">3. Building and Running a Function </td><td width="20%" align="center"><a accesskey="h" href="multi_spring-cloud-function.html">Home</a></td><td width="40%" align="right" valign="top"> 5. Standalone Web Applications</td></tr></table></div></body></html>
|
||||
@@ -1,3 +1,3 @@
|
||||
<html><head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
||||
<title>Spring Cloud Function</title><link rel="stylesheet" type="text/css" href="css/manual-multipage.css"><meta name="generator" content="DocBook XSL Stylesheets V1.78.1"><link rel="home" href="multi_spring-cloud-function.html" title="Spring Cloud Function"><link rel="next" href="multi_pr01.html" title=""></head><body class="firstpage" bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">Spring Cloud Function</th></tr><tr><td width="20%" align="left"> </td><th width="60%" align="center"> </th><td width="20%" align="right"> <a accesskey="n" href="multi_pr01.html">Next</a></td></tr></table><hr></div><div lang="en" class="book"><div class="titlepage"><div><div><h1 class="title"><a name="d0e3"></a>Spring Cloud Function</h1></div></div><hr></div><div class="toc"><p><b>Table of Contents</b></p><dl class="toc"><dt><span class="preface"><a href="multi_pr01.html"></a></span></dt><dt><span class="chapter"><a href="multi__introduction.html">1. Introduction</a></span></dt><dt><span class="chapter"><a href="multi__getting_started.html">2. Getting Started</a></span></dt><dt><span class="chapter"><a href="multi__building_and_running_a_function.html">3. Building and Running a Function</a></span></dt><dt><span class="chapter"><a href="multi__function_catalog_and_flexible_function_signatures.html">4. Function Catalog and Flexible Function Signatures</a></span></dt><dt><span class="chapter"><a href="multi__standalone_web_applications.html">5. Standalone Web Applications</a></span></dt><dt><span class="chapter"><a href="multi__standalone_streaming_applications.html">6. Standalone Streaming Applications</a></span></dt><dt><span class="chapter"><a href="multi__deploying_a_packaged_function.html">7. Deploying a Packaged Function</a></span></dt><dt><span class="chapter"><a href="multi__dynamic_compilation.html">8. Dynamic Compilation</a></span></dt><dt><span class="chapter"><a href="multi__serverless_platform_adapters.html">9. Serverless Platform Adapters</a></span></dt><dd><dl><dt><span class="section"><a href="multi__serverless_platform_adapters.html#_aws_lambda">9.1. AWS Lambda</a></span></dt><dd><dl><dt><span class="section"><a href="multi__serverless_platform_adapters.html#_introduction_2">9.1.1. Introduction</a></span></dt><dt><span class="section"><a href="multi__serverless_platform_adapters.html#_notes_on_jar_layout">9.1.2. Notes on JAR Layout</a></span></dt><dt><span class="section"><a href="multi__serverless_platform_adapters.html#_upload">9.1.3. Upload</a></span></dt><dt><span class="section"><a href="multi__serverless_platform_adapters.html#_platfom_specific_features">9.1.4. Platfom Specific Features</a></span></dt><dd><dl><dt><span class="section"><a href="multi__serverless_platform_adapters.html#_http_and_api_gateway">HTTP and API Gateway</a></span></dt></dl></dd></dl></dd><dt><span class="section"><a href="multi__serverless_platform_adapters.html#_azure_functions">9.2. Azure Functions</a></span></dt><dd><dl><dt><span class="section"><a href="multi__serverless_platform_adapters.html#_notes_on_jar_layout_2">9.2.1. Notes on JAR Layout</a></span></dt><dt><span class="section"><a href="multi__serverless_platform_adapters.html#_json_configuration">9.2.2. JSON Configuration</a></span></dt><dt><span class="section"><a href="multi__serverless_platform_adapters.html#_build">9.2.3. Build</a></span></dt><dt><span class="section"><a href="multi__serverless_platform_adapters.html#_running_the_sample">9.2.4. Running the sample</a></span></dt></dl></dd><dt><span class="section"><a href="multi__serverless_platform_adapters.html#_apache_openwhisk">9.3. Apache Openwhisk</a></span></dt><dd><dl><dt><span class="section"><a href="multi__serverless_platform_adapters.html#_quick_start">9.3.1. Quick Start</a></span></dt></dl></dd></dl></dd></dl></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"> </td><td width="20%" align="center"> </td><td width="40%" align="right"> <a accesskey="n" href="multi_pr01.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top"> </td><td width="20%" align="center"> </td><td width="40%" align="right" valign="top"> </td></tr></table></div></body></html>
|
||||
<title>Spring Cloud Function</title><link rel="stylesheet" type="text/css" href="css/manual-multipage.css"><meta name="generator" content="DocBook XSL Stylesheets V1.78.1"><link rel="home" href="multi_spring-cloud-function.html" title="Spring Cloud Function"><link rel="next" href="multi_pr01.html" title=""></head><body class="firstpage" bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">Spring Cloud Function</th></tr><tr><td width="20%" align="left"> </td><th width="60%" align="center"> </th><td width="20%" align="right"> <a accesskey="n" href="multi_pr01.html">Next</a></td></tr></table><hr></div><div lang="en" class="book"><div class="titlepage"><div><div><h1 class="title"><a name="d0e3"></a>Spring Cloud Function</h1></div></div><hr></div><div class="toc"><p><b>Table of Contents</b></p><dl class="toc"><dt><span class="preface"><a href="multi_pr01.html"></a></span></dt><dt><span class="chapter"><a href="multi__introduction.html">1. Introduction</a></span></dt><dt><span class="chapter"><a href="multi__getting_started.html">2. Getting Started</a></span></dt><dt><span class="chapter"><a href="multi__building_and_running_a_function.html">3. Building and Running a Function</a></span></dt><dt><span class="chapter"><a href="multi__function_catalog_and_flexible_function_signatures.html">4. Function Catalog and Flexible Function Signatures</a></span></dt><dd><dl><dt><span class="section"><a href="multi__function_catalog_and_flexible_function_signatures.html#_java_8_function_support">4.1. Java 8 function support</a></span></dt><dt><span class="section"><a href="multi__function_catalog_and_flexible_function_signatures.html#_kotlin_lambda_support">4.2. Kotlin Lambda support</a></span></dt></dl></dd><dt><span class="chapter"><a href="multi__standalone_web_applications.html">5. Standalone Web Applications</a></span></dt><dt><span class="chapter"><a href="multi__standalone_streaming_applications.html">6. Standalone Streaming Applications</a></span></dt><dt><span class="chapter"><a href="multi__deploying_a_packaged_function.html">7. Deploying a Packaged Function</a></span></dt><dt><span class="chapter"><a href="multi__dynamic_compilation.html">8. Dynamic Compilation</a></span></dt><dt><span class="chapter"><a href="multi__serverless_platform_adapters.html">9. Serverless Platform Adapters</a></span></dt><dd><dl><dt><span class="section"><a href="multi__serverless_platform_adapters.html#_aws_lambda">9.1. AWS Lambda</a></span></dt><dd><dl><dt><span class="section"><a href="multi__serverless_platform_adapters.html#_introduction_2">9.1.1. Introduction</a></span></dt><dt><span class="section"><a href="multi__serverless_platform_adapters.html#_notes_on_jar_layout">9.1.2. Notes on JAR Layout</a></span></dt><dt><span class="section"><a href="multi__serverless_platform_adapters.html#_upload">9.1.3. Upload</a></span></dt><dt><span class="section"><a href="multi__serverless_platform_adapters.html#_platfom_specific_features">9.1.4. Platfom Specific Features</a></span></dt><dd><dl><dt><span class="section"><a href="multi__serverless_platform_adapters.html#_http_and_api_gateway">HTTP and API Gateway</a></span></dt></dl></dd></dl></dd><dt><span class="section"><a href="multi__serverless_platform_adapters.html#_azure_functions">9.2. Azure Functions</a></span></dt><dd><dl><dt><span class="section"><a href="multi__serverless_platform_adapters.html#_notes_on_jar_layout_2">9.2.1. Notes on JAR Layout</a></span></dt><dt><span class="section"><a href="multi__serverless_platform_adapters.html#_json_configuration">9.2.2. JSON Configuration</a></span></dt><dt><span class="section"><a href="multi__serverless_platform_adapters.html#_build">9.2.3. Build</a></span></dt><dt><span class="section"><a href="multi__serverless_platform_adapters.html#_running_the_sample">9.2.4. Running the sample</a></span></dt></dl></dd><dt><span class="section"><a href="multi__serverless_platform_adapters.html#_apache_openwhisk">9.3. Apache Openwhisk</a></span></dt><dd><dl><dt><span class="section"><a href="multi__serverless_platform_adapters.html#_quick_start">9.3.1. Quick Start</a></span></dt></dl></dd></dl></dd></dl></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"> </td><td width="20%" align="center"> </td><td width="40%" align="right"> <a accesskey="n" href="multi_pr01.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top"> </td><td width="20%" align="center"> </td><td width="40%" align="right" valign="top"> </td></tr></table></div></body></html>
|
||||
@@ -1,6 +1,6 @@
|
||||
<html><head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
||||
<title>Spring Cloud Function</title><link rel="stylesheet" type="text/css" href="css/manual-singlepage.css"><meta name="generator" content="DocBook XSL Stylesheets V1.78.1"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div lang="en" class="book"><div class="titlepage"><div><div><h1 class="title"><a name="d0e3"></a>Spring Cloud Function</h1></div></div><hr></div><div class="toc"><p><b>Table of Contents</b></p><dl class="toc"><dt><span class="preface"><a href="#d0e9"></a></span></dt><dt><span class="chapter"><a href="#_introduction">1. Introduction</a></span></dt><dt><span class="chapter"><a href="#_getting_started">2. Getting Started</a></span></dt><dt><span class="chapter"><a href="#_building_and_running_a_function">3. Building and Running a Function</a></span></dt><dt><span class="chapter"><a href="#_function_catalog_and_flexible_function_signatures">4. Function Catalog and Flexible Function Signatures</a></span></dt><dt><span class="chapter"><a href="#_standalone_web_applications">5. Standalone Web Applications</a></span></dt><dt><span class="chapter"><a href="#_standalone_streaming_applications">6. Standalone Streaming Applications</a></span></dt><dt><span class="chapter"><a href="#_deploying_a_packaged_function">7. Deploying a Packaged Function</a></span></dt><dt><span class="chapter"><a href="#_dynamic_compilation">8. Dynamic Compilation</a></span></dt><dt><span class="chapter"><a href="#_serverless_platform_adapters">9. Serverless Platform Adapters</a></span></dt><dd><dl><dt><span class="section"><a href="#_aws_lambda">9.1. AWS Lambda</a></span></dt><dd><dl><dt><span class="section"><a href="#_introduction_2">9.1.1. Introduction</a></span></dt><dt><span class="section"><a href="#_notes_on_jar_layout">9.1.2. Notes on JAR Layout</a></span></dt><dt><span class="section"><a href="#_upload">9.1.3. Upload</a></span></dt><dt><span class="section"><a href="#_platfom_specific_features">9.1.4. Platfom Specific Features</a></span></dt><dd><dl><dt><span class="section"><a href="#_http_and_api_gateway">HTTP and API Gateway</a></span></dt></dl></dd></dl></dd><dt><span class="section"><a href="#_azure_functions">9.2. Azure Functions</a></span></dt><dd><dl><dt><span class="section"><a href="#_notes_on_jar_layout_2">9.2.1. Notes on JAR Layout</a></span></dt><dt><span class="section"><a href="#_json_configuration">9.2.2. JSON Configuration</a></span></dt><dt><span class="section"><a href="#_build">9.2.3. Build</a></span></dt><dt><span class="section"><a href="#_running_the_sample">9.2.4. Running the sample</a></span></dt></dl></dd><dt><span class="section"><a href="#_apache_openwhisk">9.3. Apache Openwhisk</a></span></dt><dd><dl><dt><span class="section"><a href="#_quick_start">9.3.1. Quick Start</a></span></dt></dl></dd></dl></dd></dl></div><div class="preface"><div class="titlepage"><div><div><h1 class="title"><a name="d0e9" href="#d0e9"></a></h1></div></div></div><p>Mark Fisher, Dave Syer, Oleg Zhurakousky</p><p></p></div><div class="chapter"><div class="titlepage"><div><div><h1 class="title"><a name="_introduction" href="#_introduction"></a>1. Introduction</h1></div></div></div><p>Spring Cloud Function is a project with the following high-level goals:</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">Promote the implementation of business logic via functions.</li><li class="listitem">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.</li><li class="listitem">Support a uniform programming model across serverless providers, as well as the ability to run standalone (locally or in a PaaS).</li><li class="listitem">Enable Spring Boot features (auto-configuration, dependency injection, metrics) on serverless providers.</li></ul></div><p>It abstracts away all of the transport details and
|
||||
<title>Spring Cloud Function</title><link rel="stylesheet" type="text/css" href="css/manual-singlepage.css"><meta name="generator" content="DocBook XSL Stylesheets V1.78.1"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div lang="en" class="book"><div class="titlepage"><div><div><h1 class="title"><a name="d0e3"></a>Spring Cloud Function</h1></div></div><hr></div><div class="toc"><p><b>Table of Contents</b></p><dl class="toc"><dt><span class="preface"><a href="#d0e9"></a></span></dt><dt><span class="chapter"><a href="#_introduction">1. Introduction</a></span></dt><dt><span class="chapter"><a href="#_getting_started">2. Getting Started</a></span></dt><dt><span class="chapter"><a href="#_building_and_running_a_function">3. Building and Running a Function</a></span></dt><dt><span class="chapter"><a href="#_function_catalog_and_flexible_function_signatures">4. Function Catalog and Flexible Function Signatures</a></span></dt><dd><dl><dt><span class="section"><a href="#_java_8_function_support">4.1. Java 8 function support</a></span></dt><dt><span class="section"><a href="#_kotlin_lambda_support">4.2. Kotlin Lambda support</a></span></dt></dl></dd><dt><span class="chapter"><a href="#_standalone_web_applications">5. Standalone Web Applications</a></span></dt><dt><span class="chapter"><a href="#_standalone_streaming_applications">6. Standalone Streaming Applications</a></span></dt><dt><span class="chapter"><a href="#_deploying_a_packaged_function">7. Deploying a Packaged Function</a></span></dt><dt><span class="chapter"><a href="#_dynamic_compilation">8. Dynamic Compilation</a></span></dt><dt><span class="chapter"><a href="#_serverless_platform_adapters">9. Serverless Platform Adapters</a></span></dt><dd><dl><dt><span class="section"><a href="#_aws_lambda">9.1. AWS Lambda</a></span></dt><dd><dl><dt><span class="section"><a href="#_introduction_2">9.1.1. Introduction</a></span></dt><dt><span class="section"><a href="#_notes_on_jar_layout">9.1.2. Notes on JAR Layout</a></span></dt><dt><span class="section"><a href="#_upload">9.1.3. Upload</a></span></dt><dt><span class="section"><a href="#_platfom_specific_features">9.1.4. Platfom Specific Features</a></span></dt><dd><dl><dt><span class="section"><a href="#_http_and_api_gateway">HTTP and API Gateway</a></span></dt></dl></dd></dl></dd><dt><span class="section"><a href="#_azure_functions">9.2. Azure Functions</a></span></dt><dd><dl><dt><span class="section"><a href="#_notes_on_jar_layout_2">9.2.1. Notes on JAR Layout</a></span></dt><dt><span class="section"><a href="#_json_configuration">9.2.2. JSON Configuration</a></span></dt><dt><span class="section"><a href="#_build">9.2.3. Build</a></span></dt><dt><span class="section"><a href="#_running_the_sample">9.2.4. Running the sample</a></span></dt></dl></dd><dt><span class="section"><a href="#_apache_openwhisk">9.3. Apache Openwhisk</a></span></dt><dd><dl><dt><span class="section"><a href="#_quick_start">9.3.1. Quick Start</a></span></dt></dl></dd></dl></dd></dl></div><div class="preface"><div class="titlepage"><div><div><h1 class="title"><a name="d0e9" href="#d0e9"></a></h1></div></div></div><p>Mark Fisher, Dave Syer, Oleg Zhurakousky</p><p></p></div><div class="chapter"><div class="titlepage"><div><div><h1 class="title"><a name="_introduction" href="#_introduction"></a>1. Introduction</h1></div></div></div><p>Spring Cloud Function is a project with the following high-level goals:</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">Promote the implementation of business logic via functions.</li><li class="listitem">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.</li><li class="listitem">Support a uniform programming model across serverless providers, as well as the ability to run standalone (locally or in a PaaS).</li><li class="listitem">Enable Spring Boot features (auto-configuration, dependency injection, metrics) on serverless providers.</li></ul></div><p>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.</p><p>Here’s a complete, executable, testable Spring Boot application
|
||||
(implementing a simple string manipulation):</p><pre class="programlisting"><em><span class="hl-annotation" style="color: gray">@SpringBootApplication</span></em>
|
||||
@@ -46,13 +46,14 @@ POJO) JSON. TBD: support for <code class="literal">Flux<Message<Pojo>&g
|
||||
<code class="literal">Pojo</code> types (Fluxes implied and implemented by the framework).</p><p>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.</p></div><div class="chapter"><div class="titlepage"><div><div><h1 class="title"><a name="_function_catalog_and_flexible_function_signatures" href="#_function_catalog_and_flexible_function_signatures"></a>4. Function Catalog and Flexible Function Signatures</h1></div></div></div><p>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 <code class="literal">Function<String,String></code>, for
|
||||
instance, and the <code class="literal">FunctionCatalog</code> will wrap it into a
|
||||
<code class="literal">Function<Flux<String>,Flux<String>></code>. Users don’t normally have to
|
||||
care about the <code class="literal">FunctionCatalog</code> at all, but it is useful to know what
|
||||
kind of functions are supported in user code.</p><p>Generally speaking users can expect that if they write a function for
|
||||
exposing different functions over different physical transports.</p></div><div class="chapter"><div class="titlepage"><div><div><h1 class="title"><a name="_function_catalog_and_flexible_function_signatures" href="#_function_catalog_and_flexible_function_signatures"></a>4. Function Catalog and Flexible Function Signatures</h1></div></div></div><p>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 <code class="literal">FunctionCatalog</code>, using primitives
|
||||
defined by the <a class="link" href="https://projectreactor.io/" target="_top">Project Reactor</a> (i.e., <code class="literal">Flux<T></code> and <code class="literal">Mono<T></code>).
|
||||
Users can supply a bean of type <code class="literal">Function<String,String></code>, for instance, and the <code class="literal">FunctionCatalog</code> will wrap it into a
|
||||
<code class="literal">Function<Flux<String>,Flux<String>></code>.</p><p>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.</p><p>While users don’t normally have to care about the <code class="literal">FunctionCatalog</code> at all, it is useful to know what
|
||||
kind of functions are supported in user code.</p><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="_java_8_function_support" href="#_java_8_function_support"></a>4.1 Java 8 function support</h2></div></div></div><p>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 <code class="literal">Flux</code> of the same type. If the user writes
|
||||
a function using <code class="literal">Message</code> (from spring-messaging) it will receive and
|
||||
@@ -63,13 +64,24 @@ need to write <code class="literal">Consumer<Flux<?>></code>, but if
|
||||
remember to subscribe to the input flux. If you declare a <code class="literal">Consumer</code>
|
||||
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.</p><p>A function catalog can contain a <code class="literal">Supplier</code> and a <code class="literal">Function</code> (or
|
||||
<code class="literal">Consumer</code>) with the same name (like a GET and a POST to the same
|
||||
resource). It can even contain a <code class="literal">Consumer<Flux<>></code> with the same name
|
||||
as a <code class="literal">Function</code>, but it cannot contain a <code class="literal">Consumer<T></code> and a
|
||||
<code class="literal">Function<T,S></code> with the same name when <code class="literal">T</code> is not a <code class="literal">Publisher</code>
|
||||
because the consumer would be converted to a <code class="literal">Function</code> and only one
|
||||
of them can be registered.</p></div><div class="chapter"><div class="titlepage"><div><div><h1 class="title"><a name="_standalone_web_applications" href="#_standalone_web_applications"></a>5. Standalone Web Applications</h1></div></div></div><p>The <code class="literal">spring-cloud-function-web</code> module has autoconfiguration that
|
||||
a controlled way.</p></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="_kotlin_lambda_support" href="#_kotlin_lambda_support"></a>4.2 Kotlin Lambda support</h2></div></div></div><p>We also provide support for Kotlin lambdas (since v2.0).
|
||||
Consider the following:</p><pre class="programlisting"><em><span class="hl-annotation" style="color: gray">@Bean</span></em>
|
||||
open fun kotlinSupplier(): () -> String {
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">return</span> { <span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"Hello from Kotlin"</span> }
|
||||
}
|
||||
|
||||
<em><span class="hl-annotation" style="color: gray">@Bean</span></em>
|
||||
open fun kotlinFunction(): (String) -> String {
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">return</span> { it.toUpperCase() }
|
||||
}
|
||||
|
||||
<em><span class="hl-annotation" style="color: gray">@Bean</span></em>
|
||||
open fun kotlinConsumer(): (String) -> Unit {
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">return</span> { println(it) }
|
||||
}</pre><p>The above represents Kotlin lambdas configured as Spring beans. The signature of each maps to a Java equivalent of
|
||||
<code class="literal">Supplier</code>, <code class="literal">Function</code> and <code class="literal">Consumer</code>, 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.</p></div></div><div class="chapter"><div class="titlepage"><div><div><h1 class="title"><a name="_standalone_web_applications" href="#_standalone_web_applications"></a>5. Standalone Web Applications</h1></div></div></div><p>The <code class="literal">spring-cloud-function-web</code> module has autoconfiguration that
|
||||
activates when it is included in a Spring Boot web application (with
|
||||
MVC support). There is also a <code class="literal">spring-cloud-starter-function-web</code> to
|
||||
collect all the optional dependnecies in case you just want a simple
|
||||
|
||||
@@ -119,13 +119,18 @@ exposing different functions over different physical transports.</simpara>
|
||||
</chapter>
|
||||
<chapter xml:id="_function_catalog_and_flexible_function_signatures">
|
||||
<title>Function Catalog and Flexible Function Signatures</title>
|
||||
<simpara>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 <literal>Function<String,String></literal>, for
|
||||
instance, and the <literal>FunctionCatalog</literal> will wrap it into a
|
||||
<literal>Function<Flux<String>,Flux<String>></literal>. Users don’t normally have to
|
||||
care about the <literal>FunctionCatalog</literal> at all, but it is useful to know what
|
||||
<simpara>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 <literal>FunctionCatalog</literal>, using primitives
|
||||
defined by the <link xl:href="https://projectreactor.io/">Project Reactor</link> (i.e., <literal>Flux<T></literal> and <literal>Mono<T></literal>).
|
||||
Users can supply a bean of type <literal>Function<String,String></literal>, for instance, and the <literal>FunctionCatalog</literal> will wrap it into a
|
||||
<literal>Function<Flux<String>,Flux<String>></literal>.</simpara>
|
||||
<simpara>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.</simpara>
|
||||
<simpara>While users don’t normally have to care about the <literal>FunctionCatalog</literal> at all, it is useful to know what
|
||||
kind of functions are supported in user code.</simpara>
|
||||
<section xml:id="_java_8_function_support">
|
||||
<title>Java 8 function support</title>
|
||||
<simpara>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 <literal>Flux</literal> of the same type. If the user writes
|
||||
@@ -195,13 +200,30 @@ remember to subscribe to the input flux. If you declare a <literal>Consumer</lit
|
||||
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.</simpara>
|
||||
<simpara>A function catalog can contain a <literal>Supplier</literal> and a <literal>Function</literal> (or
|
||||
<literal>Consumer</literal>) with the same name (like a GET and a POST to the same
|
||||
resource). It can even contain a <literal>Consumer<Flux<>></literal> with the same name
|
||||
as a <literal>Function</literal>, but it cannot contain a <literal>Consumer<T></literal> and a
|
||||
<literal>Function<T,S></literal> with the same name when <literal>T</literal> is not a <literal>Publisher</literal>
|
||||
because the consumer would be converted to a <literal>Function</literal> and only one
|
||||
of them can be registered.</simpara>
|
||||
</section>
|
||||
<section xml:id="_kotlin_lambda_support">
|
||||
<title>Kotlin Lambda support</title>
|
||||
<simpara>We also provide support for Kotlin lambdas (since v2.0).
|
||||
Consider the following:</simpara>
|
||||
<programlisting language="java" linenumbering="unnumbered">@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) }
|
||||
}</programlisting>
|
||||
<simpara>The above represents Kotlin lambdas configured as Spring beans. The signature of each maps to a Java equivalent of
|
||||
<literal>Supplier</literal>, <literal>Function</literal> and <literal>Consumer</literal>, 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.</simpara>
|
||||
</section>
|
||||
</chapter>
|
||||
<chapter xml:id="_standalone_web_applications">
|
||||
<title>Standalone Web Applications</title>
|
||||
|
||||
Reference in New Issue
Block a user