Add support for different handler->function mappings in Azure

This commit is contained in:
Dave Syer
2018-08-16 15:18:59 +01:00
parent 3baaa45648
commit f09f750c39
13 changed files with 410 additions and 140 deletions

View File

@@ -1,6 +1,4 @@
extensions.csproj
obj/
lib/
node/
package-lock.json
node_modules/
etc/

View File

@@ -24,7 +24,9 @@
<functionAppName>function-sample-azure</functionAppName>
<functionAppRegion>westus</functionAppRegion>
<functionResourceGroup>java-function-group</functionResourceGroup>
<stagingDirectory>${project.build.directory}/azure-functions/${functionAppName}</stagingDirectory>
<start-class>example.Config</start-class>
<wrapper.version>1.0.11.RELEASE</wrapper.version>
</properties>
<dependencies>
@@ -61,6 +63,26 @@
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-clean-plugin</artifactId>
<configuration>
<filesets>
<fileset>
<directory>${basedir}</directory>
<includes>
<include>obj/**</include>
</includes>
</fileset>
<fileset>
<directory>${basedir}</directory>
<includes>
<include>extensions.csproj</include>
</includes>
</fileset>
</filesets>
</configuration>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
@@ -68,7 +90,7 @@
<plugin>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-functions-maven-plugin</artifactId>
<version>1.0.0-beta-1</version>
<version>1.0.0-beta-4</version>
</plugin>
</plugins>
</pluginManagement>
@@ -81,6 +103,26 @@
<skip>true</skip>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>prepare-package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${stagingDirectory}/lib</outputDirectory>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>false</overWriteSnapshots>
<overWriteIfNewer>true</overWriteIfNewer>
<includeScope>runtime</includeScope>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-functions-maven-plugin</artifactId>
@@ -93,8 +135,20 @@
<name>FUNCTIONS_EXTENSION_VERSION</name>
<value>beta</value>
</property>
<property>
<name>MSDEPLOY_RENAME_LOCKED_FILES</name>
<value>1</value>
</property>
</appSettings>
</configuration>
<executions>
<execution>
<id>package-functions</id>
<goals>
<goal>package</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
@@ -121,42 +175,17 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<configuration>
<createDependencyReducedPom>false</createDependencyReducedPom>
<shadedArtifactAttached>true</shadedArtifactAttached>
<shadedClassifierName>azure</shadedClassifierName>
<outputDirectory>${project.build.directory}/azure-functions/${functionAppName}</outputDirectory>
</configuration>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<dependencies>
<dependency>
<groupId>org.springframework.boot.experimental</groupId>
<artifactId>spring-boot-thin-layout</artifactId>
<version>${wrapper.version}</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<id>azure</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<inherited>false</inherited>
<configuration>
<attach>false</attach>
<descriptors>
<descriptor>${basedir}/src/assembly/azure.xml</descriptor>
</descriptors>
<outputDirectory>${project.build.directory}/azure-functions</outputDirectory>
<appendAssemblyId>false</appendAssemblyId>
<finalName>${functionAppName}</finalName>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

View File

@@ -1,20 +0,0 @@
<assembly
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3 http://maven.apache.org/xsd/assembly-1.1.3.xsd">
<id>azure</id>
<formats>
<format>zip</format>
</formats>
<baseDirectory></baseDirectory>
<fileSets>
<fileSet>
<directory>${project.build.directory}/azure-functions/${functionAppName}</directory>
<outputDirectory></outputDirectory>
<includes>
<include>*-azure.jar</include>
<include>**/*.json</include>
</includes>
</fileSet>
</fileSets>
</assembly>

View File

@@ -2,6 +2,7 @@
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "",
"AzureWebJobsDashboard": ""
"AzureWebJobsDashboard": "",
"FUNCTIONS_WORKER_RUNTIME": "java"
}
}

View File

@@ -1,21 +0,0 @@
{
"scriptFile": "../function-sample-azure-2.0.0.BUILD-SNAPSHOT-azure.jar",
"entryPoint": "example.FooHandler.execute",
"bindings": [
{
"type": "httpTrigger",
"name": "foo",
"direction": "in",
"authLevel": "anonymous",
"methods": [
"post"
]
},
{
"type": "http",
"name": "$return",
"direction": "out"
}
],
"disabled": false
}

View File

@@ -17,6 +17,10 @@
package example;
import com.microsoft.azure.functions.ExecutionContext;
import com.microsoft.azure.functions.HttpMethod;
import com.microsoft.azure.functions.annotation.AuthorizationLevel;
import com.microsoft.azure.functions.annotation.FunctionName;
import com.microsoft.azure.functions.annotation.HttpTrigger;
import org.springframework.cloud.function.adapter.azure.AzureSpringBootRequestHandler;
@@ -24,8 +28,11 @@ import org.springframework.cloud.function.adapter.azure.AzureSpringBootRequestHa
* @author Soby Chacko
*/
public class FooHandler extends AzureSpringBootRequestHandler<Foo, Bar> {
public Bar execute(Foo foo, ExecutionContext context) {
@FunctionName("uppercase")
public Bar execute(
@HttpTrigger(name = "req", methods = { HttpMethod.GET,
HttpMethod.POST }, authLevel = AuthorizationLevel.ANONYMOUS) Foo foo,
ExecutionContext context) {
return handleRequest(foo, context);
}