Sync docs from master to gh-pages
This commit is contained in:
@@ -632,6 +632,21 @@ You can write an app with a single <literal>@Bean</literal> of type <literal>Fun
|
||||
}</programlisting>
|
||||
<simpara>This Azure handler will delegate to a <literal>Function<Foo,Bar></literal> bean (or a <literal>Function<Publisher<Foo>,Publisher<Bar>></literal>). Some Azure triggers (e.g. <literal>@CosmosDBTrigger</literal>) result in a input type of <literal>List</literal> and in that case you can bind to <literal>List</literal> in the Azure handler, or <literal>String</literal> (the raw JSON). The <literal>List</literal> input delegates to a <literal>Function</literal> with input type <literal>Map<String,Object></literal>, or <literal>Publisher</literal> or <literal>List</literal> of the same type. The output of the <literal>Function</literal> can be a <literal>List</literal> (one-for-one) or a single value (aggregation), and the output binding in the Azure declaration should match.</simpara>
|
||||
<simpara>If your app has more than one <literal>@Bean</literal> of type <literal>Function</literal> etc. then you can choose the one to use by configuring <literal>function.name</literal>. Or if you make the <literal>@FunctionName</literal> in the Azure handler method match the function name it should work that way (also for function apps with multiple functions). The functions are extracted from the Spring Cloud <literal>FunctionCatalog</literal> so the default function names are the same as the bean names.</simpara>
|
||||
<section xml:id="_accessing_azure_executioncontext">
|
||||
<title>Accessing Azure ExecutionContext</title>
|
||||
<simpara>Some time there is a need to access the target execution context provided by Azure runtime in the form of <literal>com.microsoft.azure.functions.ExecutionContext</literal>.
|
||||
For example one of such needs is logging, so it can appear in the Azure console.</simpara>
|
||||
<simpara>For that purpose Spring Cloud Function will register <literal>ExecutionContext</literal> as bean in the Application context, so it could be injected into your function.
|
||||
For example</simpara>
|
||||
<programlisting language="java" linenumbering="unnumbered">@Bean
|
||||
public Function<Foo, Bar> uppercase(ExecutionContext targetContext) {
|
||||
return foo -> {
|
||||
targetContext.getLogger().info("Invoking 'uppercase' on " + foo.getValue());
|
||||
return new Bar(foo.getValue().toUpperCase());
|
||||
};
|
||||
}</programlisting>
|
||||
<simpara>Normally type-based injection should suffice, however if need to you can also utilise the bean name under which it is registered which is <literal>targetExecutionContext</literal>.</simpara>
|
||||
</section>
|
||||
<section xml:id="_notes_on_jar_layout_2">
|
||||
<title>Notes on JAR Layout</title>
|
||||
<simpara>You don’t need the Spring Cloud Function Web at runtime in Azure, so you can exclude this before you create the JAR you deploy to Azure, but it won’t be used if you include it so it doesn’t hurt to leave it in. A function application on Azure is an archive generated by the Maven plugin. The function lives in the JAR file generated by this project. The sample creates it as an executable jar, using the thin layout, so that Azure can find the handler classes. If you prefer you can just use a regular flat JAR file. The dependencies should <emphasis role="strong">not</emphasis> be included.</simpara>
|
||||
|
||||
Reference in New Issue
Block a user