diff --git a/src/main/java/com/microsoft/azure/functions/annotation/CosmosDBInput.java b/src/main/java/com/microsoft/azure/functions/annotation/CosmosDBInput.java index d7f6324..b731152 100644 --- a/src/main/java/com/microsoft/azure/functions/annotation/CosmosDBInput.java +++ b/src/main/java/com/microsoft/azure/functions/annotation/CosmosDBInput.java @@ -16,12 +16,30 @@ * The parameter type can be one of the following:
* *The following example shows a Java function that retrieves a single document. The function is triggered by an + * HTTP request that uses a query string to specify the ID to look up. That ID is used to retrieve a ToDoItem document + * from the specified database and collection. A sample URL would be like: http://localhost:7071/api/getItem?id=myid.
+ * + *{@literal @}FunctionName("getItem") + * public String cosmosDbQueryById( + * {@literal @}HttpTrigger(name = "req", + * methods = {HttpMethod.GET}, + * authLevel = AuthorizationLevel.ANONYMOUS) Optional<String> dummy, + * {@literal @}CosmosDBInput(name = "database", + * databaseName = "ToDoList", + * collectionName = "Items", + * id = "{Query.id}", + * connectionStringSetting = "AzureCosmosDBConnection") Optional<String> item + * ) { + * return item.orElse("Not found"); + * }+ * * @since 1.0.0 */ @Retention(RetentionPolicy.RUNTIME) diff --git a/src/main/java/com/microsoft/azure/functions/annotation/CosmosDBOutput.java b/src/main/java/com/microsoft/azure/functions/annotation/CosmosDBOutput.java index 8f379f7..9f9929e 100644 --- a/src/main/java/com/microsoft/azure/functions/annotation/CosmosDBOutput.java +++ b/src/main/java/com/microsoft/azure/functions/annotation/CosmosDBOutput.java @@ -16,11 +16,20 @@ * The parameter type should be OutputBinding<T>, where T could be one of: * *
The following example shows a Java function that adds a document to a database, using data provided in the body of an HTTP Post request.
* + *{@literal @}FunctionName("addItem") + *{@literal @}CosmosDBOutput(name = "database", databaseName = "ToDoList", collectionName = "Items", connectionStringSetting = "AzureCosmosDBConnection") + * public String cosmosDbAddItem( + * {@literal @}HttpTrigger(name = "request", methods = {HttpMethod.POST}, authLevel = AuthorizationLevel.ANONYMOUS) final String message + * ) { + * return "{ \"id\": \"" + System.currentTimeMillis() + "\", \"description\": \"" + message + "\" }"; + * }+ * * @since 1.0.0 */ @Retention(RetentionPolicy.RUNTIME) diff --git a/src/main/java/com/microsoft/azure/functions/annotation/CosmosDBTrigger.java b/src/main/java/com/microsoft/azure/functions/annotation/CosmosDBTrigger.java index b4b8157..206d89d 100644 --- a/src/main/java/com/microsoft/azure/functions/annotation/CosmosDBTrigger.java +++ b/src/main/java/com/microsoft/azure/functions/annotation/CosmosDBTrigger.java @@ -16,23 +16,28 @@ * data is changed. The parameter type can be one of the following: * *
The following example shows a cosmos db trigger which logs the count of the returned items:
+ *The following example shows a Java function that is invoked when there are inserts or updates in the specified + * database and collection.
* - *{@literal @}FunctionName("cdbprocessor") - * public void cosmosDbProcessor( - * {@literal @}CosmosDBTrigger(name = "items", - * databaseName = "mydbname", - * collectionName = "mycollname", - * leaseCollectionName = "", - * connectionStringSetting = "myconnvarname") MyDataItem[] items, + *{@literal @}FunctionName("cosmosDBMonitor") + * public void cosmosDbLog( + * {@literal @}CosmosDBTrigger(name = "database", + * databaseName = "ToDoList", + * collectionName = "Items", + * leaseCollectionName = "leases", + * createLeaseCollectionIfNotExists = true, + * connectionStringSetting = "AzureCosmosDBConnection") List<Map<String, String>> items, * final ExecutionContext context * ) { - * context.getLogger().info(items.length); + * context.getLogger().info(items.size() + " item(s) is/are inserted."); + * if (!items.isEmpty()) { + * context.getLogger().info("The ID of the first item is: " + items.get(0).get("id")); + * } * }* * @since 1.0.0 diff --git a/src/main/java/com/microsoft/azure/functions/annotation/EventGridTrigger.java b/src/main/java/com/microsoft/azure/functions/annotation/EventGridTrigger.java index 5df798c..ebed066 100644 --- a/src/main/java/com/microsoft/azure/functions/annotation/EventGridTrigger.java +++ b/src/main/java/com/microsoft/azure/functions/annotation/EventGridTrigger.java @@ -21,14 +21,14 @@ *
The following example shows an event grid trigger which prints out the object:
+ *The following example shows a Java function that prints out an event:
* - *{@literal @}FunctionName("egprocessor") - * public void eventGridProcessor( - * {@literal @}EventGridTrigger(name = "obj") MyModel obj, + *{@literal @}FunctionName("eventGridMonitor") + * public void logEvent( + * {@literal @}EventGridTrigger(name = "event") String content, * final ExecutionContext context * ) { - * context.getLogger().info(obj.toString()); + * context.getLogger().info(content); * }* * @since 1.0.0