22 lines
4.8 KiB
HTML
22 lines
4.8 KiB
HTML
<html><head>
|
|
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
|
<title>14. Azure Functions</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__upload.html" title="13. Upload"><link rel="next" href="multi__build_2.html" title="15. Build"></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">14. Azure Functions</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="multi__upload.html">Prev</a> </td><th width="60%" align="center"> </th><td width="20%" align="right"> <a accesskey="n" href="multi__build_2.html">Next</a></td></tr></table><hr></div><div class="chapter"><div class="titlepage"><div><div><h1 class="title"><a name="_azure_functions" href="#_azure_functions"></a>14. Azure Functions</h1></div></div></div><p>The <a class="link" href="https://azure.microsoft.com" target="_top">Azure</a> adapter bootstraps a Spring Cloud Function context and channels function calls from the Azure framework into the user functions, using Spring Boot configuration where necessary. Azure Functions has quite a unique, but invasive programming model, involving annotations in user code that are specific to the platform. The Spring Cloud Function Azure adapter trades the convenience of these annotations for portability of the function implementations. Instead of using the annotations you have to write some JSON by hand (at least for now) to guide the platform to call the right methods in the adapter.</p><p>The adapter has a generic http request handler that you can use.
|
|
There is a <code class="literal">AzureSpringBootRequestHandler</code> which you must extend, and provide the input and output types as type parameters (enabling Azure to inspect the class and do the JSON conversions itself).</p><p>If your app has more than one <code class="literal">@Bean</code> of type <code class="literal">Function</code> etc. then you can choose the one to use by configuring <code class="literal">function.name</code>.
|
|
The functions are extracted from the Spring Cloud <code class="literal">FunctionCatalog</code>.</p><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="_notes_on_jar_layout_2" href="#_notes_on_jar_layout_2"></a>14.1 Notes on JAR Layout</h2></div></div></div><p>You don’t need the Spring Cloud Function Web at runtime in Azure, so you need to exclude this before you create the JAR you deploy to Azure.
|
|
A function application on Azure has to be shaded, but a Spring Boot standalone application does not, so you can run the same app using 2 separate jars (as per the sample here).
|
|
The sample app creates the shaded jar file, with an <code class="literal">azure</code> classifier for deploying in Azure.</p></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="_json_configuration" href="#_json_configuration"></a>14.2 JSON Configuration</h2></div></div></div><p>The Azure tooling needs to find some JSON configuration files to tell it how to deploy and integrate the function (e.g. which Java class to use as the entry point, and which triggers to use). Those files can be created with the Maven plugin for a non-Spring function, but the tooling doesn’t work yet with the adapter in its current form. There is an example <code class="literal">function.json</code> in the sample which hooks the function up as an HTTP endpoint:</p><pre class="screen">{
|
|
"scriptFile" : "../function-sample-azure-1.0.0.BUILD-SNAPSHOT-azure.jar",
|
|
"entryPoint" : "example.FooHandler.execute",
|
|
"bindings" : [ {
|
|
"type" : "httpTrigger",
|
|
"name" : "foo",
|
|
"direction" : "in",
|
|
"authLevel" : "anonymous",
|
|
"methods" : [ "get", "post" ]
|
|
}, {
|
|
"type" : "http",
|
|
"name" : "$return",
|
|
"direction" : "out"
|
|
} ],
|
|
"disabled" : false
|
|
}</pre></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="multi__upload.html">Prev</a> </td><td width="20%" align="center"> </td><td width="40%" align="right"> <a accesskey="n" href="multi__build_2.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">13. Upload </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"> 15. Build</td></tr></table></div></body></html> |