I'm working on a Java Function that has a timer trigger and try to insert a simple record in a DocumentDB collection. The Java code is the following
import java.util.Calendar;
import java.util.UUID;
import com.microsoft.azure.documentdb.Document;
import com.microsoft.azure.serverless.functions.ExecutionContext;
import com.microsoft.azure.serverless.functions.annotation.*;
public class DocumentDBFunction {
@FunctionName("documentDBFunction")
@DocumentDBOutput(name = "testdoc",
createIfNotExists = true,
databaseName = "functiondb",
collectionName="functioncoll",
connection = "CosmosDBConnectionString")
public Document functionHandler(
@TimerTrigger(name = "timerInfo", schedule = "*/30 * * * * *")
String timerInfo,
final ExecutionContext executionContext) {
String randomString=UUID.randomUUID().toString();
executionContext.getLogger().info("Insert obj documentDB: " + randomString);
Document document=new Document();
document.set("id",randomString);
document.set("_id",randomString);
document.set("uuid", randomString);
return document;
}
}
CosmosDBConnectionString is available in AppSetting and I also created the collection. Function.json is the following
{
"scriptFile": "../azurefunctions-1.0-SNAPSHOT.jar",
"entryPoint": "test.azure.functions.DocumentDBFunction.functionHandler",
"bindings": [
{
"type": "timerTrigger",
"name": "timerInfo",
"direction": "in",
"schedule": "*/30 * * * * *"
},
{
"type": "documentdb",
"name": "$return",
"direction": "out",
"databaseName": "functiondb",
"collectionName": "functioncoll",
"connection": "CosmosDBConnectionString",
"createIfNotExists": true
}
],
"disabled": false
}
If I run this function I haven'n error on the log files, but there isn't a new object in the DocumentDB collection. Any ideas? Comments and suggestions are welcome