Can anyone please help me figure out an Azure function in a Maven Java project to read a MongoDB database?
I am struggling to find any useful examples on github or in Microsoft's Azure documentation.
Here's what I have so far - although it fails to compile because it can't access a class I've defined in a separate library I mean to include.
My pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<name>CRUD Azure Functions</name>
<version>1.0.0</version>
<artifactId>crud-azure-functions</artifactId>
<description>Experimenting with Azure Functions</description>
<packaging>jar</packaging>
<parent>
<artifactId>my-parent-module</artifactId>
<groupId>com.snoop.dougg</groupId>
<version>1.0.0</version>
</parent>
<properties>
<start-class>com.snoop.dougg.azure</start-class>
</properties>
<dependencies>
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-functions-java-core</artifactId>
<version>1.0.0-beta-2</version>
</dependency>
<dependency>
<groupId>com.snoop.dougg</groupId>
<artifactId>my-common-lib</artifactId>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-functions-maven-plugin</artifactId>
<version>0.1.7</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.1.0</version>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-functions-maven-plugin</artifactId>
<configuration>
<resourceGroup>java-functions-group</resourceGroup>
<appName>crud-azure-functions</appName>
<region>Central US</region>
<appSettings>
<property>
<name>FUNCTIONS_EXTENSION_VERSION</name>
<value>beta</value>
</property>
</appSettings>
</configuration>
<executions>
<execution>
<id>package-functions</id>
<goals>
<goal>package</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<id>copy-resources</id>
<phase>package</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<overwrite>true</overwrite>
<outputDirectory>${project.basedir}</outputDirectory>
<resources>
<resource>
<directory>${project.basedir}</directory>
<includes>
<include>**/*jar</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<configuration>
<outputFile>${project.basedir}/${project.artifactId}-${project.version}.jar</outputFile>
<shadedArtifactAttached>false</shadedArtifactAttached>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
And then here's my Java code:
package com.snoop.dougg.azure;
import com.snoop.dougg.common.model.mongodb.Item;
import com.microsoft.azure.serverless.functions.ExecutionContext;
import com.microsoft.azure.serverless.functions.HttpRequestMessage;
import com.microsoft.azure.serverless.functions.HttpResponseMessage;
import com.microsoft.azure.serverless.functions.annotation.AuthorizationLevel;
import com.microsoft.azure.serverless.functions.annotation.FunctionName;
import com.microsoft.azure.serverless.functions.annotation.HttpTrigger;
import com.microsoft.azure.serverless.functions.annotation.TableInput;
import javax.servlet.http.HttpServletResponse;
import java.util.Optional;
public class ItemCrudFunctions {
public static void main() {}
@FunctionName("DouggHelloWorld")
public HttpResponseMessage<String> helloWorld(
@HttpTrigger(name = "req", methods = {"get"}, authLevel = AuthorizationLevel.ANONYMOUS)
HttpRequestMessage<Optional<String>> request,
final ExecutionContext context) {
return request.createResponse(HttpServletResponse.SC_OK, "Good news everyone!");
}
@FunctionName("ItemRetrieval")
public HttpResponseMessage<Item> retrieveItem(
@HttpTrigger(name = "retrieveItem",
route = "/item/{itemId}",
methods = {"get"},
authLevel = AuthorizationLevel.FUNCTION)
HttpRequestMessage<Optional<String>> requestMessage,
@TableInput(name = "itemTableInput",
tableName = "item",
connection = "AzureWebJobsStorage",
rowKey = "{itemId}") Item item) {
return requestMessage.createResponse(HttpServletResponse.SC_OK, item);
}
}
But I'm getting an error: cannot find symbol: class Item, and on top of that, I have no idea if this would even work if it did compile. I've been completely unable to find any good examples of Maven Java Azure Functions so far...


