Sync docs from master to gh-pages

This commit is contained in:
buildmaster
2019-02-28 09:05:40 +00:00
parent 7bc988b315
commit a19742e19f
4 changed files with 90 additions and 4 deletions

View File

@@ -540,6 +540,33 @@ Invoker</link> acts natively is an adapter for Spring Cloud Function jars.</simp
<simpara>The AWS sample app is written in the "functional" style (as an <literal>ApplicationContextInitializer</literal>). This is much faster on startup in Lambda than the traditional <literal>@Bean</literal> style, so if you don&#8217;t need <literal>@Beans</literal> (or <literal>@EnableAutoConfiguration</literal>) it&#8217;s a good choice. Warm starts are not affected.</simpara>
</note>
</section>
<section xml:id="_functional_bean_definitions_2">
<title>Functional Bean Definitions</title>
<simpara>Your functions will start much quicker if you can use functional bean definitions instead of <literal>@Bean</literal>. To do this make your main class
an <literal>ApplicationContextInitalizer&lt;GenericApplicationContext&gt;</literal> and use the <literal>registerBean()</literal> methods in <literal>GenericApplicationContext</literal> to
create all the beans you need. You function need sto be registered as a bean of type <literal>FunctionRegistration</literal> so that the input and
output types can be accessed by the framework. There is an example in github (the AWS sample is written in this style). It would
look something like this:</simpara>
<programlisting language="java" linenumbering="unnumbered">@SpringBootApplication
public class FuncApplication implements ApplicationContextInitializer&lt;GenericApplicationContext&gt; {
public static void main(String[] args) throws Exception {
FunctionalSpringApplication.run(FuncApplication.class, args);
}
public Function&lt;Foo, Bar&gt; function() {
return value -&gt; new Bar(value.uppercase()));
}
@Override
public void initialize(GenericApplicationContext context) {
context.registerBean("function", FunctionRegistration.class,
() -&gt; new FunctionRegistration&lt;Function&lt;Foo, Bar&gt;&gt;(function())
.type(FunctionType.from(Foo.class).to(Bar.class).getType()));
}
}</programlisting>
</section>
<section xml:id="_platfom_specific_features">
<title>Platfom Specific Features</title>
<section xml:id="_http_and_api_gateway">
@@ -579,6 +606,15 @@ Invoker</link> acts natively is an adapter for Spring Cloud Function jars.</simp
<simpara>For example, to deploy behind an API Gateway, use <literal>--handler org.springframework.cloud.function.adapter.aws.SpringBootApiGatewayRequestHandler</literal> in your AWS command line (in via the UI) and define a <literal>@Bean</literal> of type <literal>Function&lt;Message&lt;Foo&gt;,Message&lt;Bar&gt;&gt;</literal> where <literal>Foo</literal> and <literal>Bar</literal> are POJO types (the data will be marshalled and unmarshalled by AWS using Jackson).</simpara>
</section>
</section>
<section xml:id="_custom_runtime">
<title>Custom Runtime</title>
<simpara>An <link xl:href="https://docs.aws.amazon.com/lambda/latest/dg/runtimes-custom.html">AWS Lambda custom runtime</link> can be created really easily using the HTTP export features in Spring Cloud Function Web. To make this work just add Spring Cloud Function AWS and Spring Cloud Function Web as dependencies in your project and set the following in your <literal>application.properties</literal>:</simpara>
<screen>spring.cloud.function.web.export.enabled=true
spring.cloud.function.web.export.source.url=http://${AWS_LAMBDA_RUNTIME_API:localhost}/2018-06-01/runtime/invocation/next
spring.cloud.function.web.export.sink.url=http://${AWS_LAMBDA_RUNTIME_API:localhost}/2018-06-01/runtime/invocation/{{destination}}/response
spring.cloud.function.web.export.sink.name=origin|uppercase</screen>
<simpara>where "uppercase" is the name of your function ("origin" is the name of the <literal>Supplier</literal> that is provided by Spring Cloud Function Web). Then provide a <literal>bootstrap</literal> script in the root of your zip/jar that runs the Spring Boot application. The functional bean definition style works for custom runtimes too, and is faster than the <literal>@Bean</literal> style, so the example <literal>FuncApplication</literal> above would work. A custom runtime can start up much quicker even than a functional bean implementation of a Java lambda - it depends mostly on the number of classes you need to load at runtime. Spring doesn&#8217;t do very much here, so you can reduce the cold start time by only using primitive types in your function, for instance, and not doing any work in custom <literal>@PostConstruct</literal> initializers.</simpara>
</section>
</section>
<section xml:id="_azure_functions">
<title>Azure Functions</title>