Skip to content

Commit

Permalink
Add CosmosDB binding samples (Azure#34).
Browse files Browse the repository at this point in the history
  • Loading branch information
Junyi Yi committed Jul 21, 2018
1 parent 9e6ceae commit 546e322
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,26 @@
* </ul>
*
*
* <p>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.</p>
*
* <pre>{@literal @}FunctionName("getItem")
* public String cosmosDbQueryById(
* {@literal @}HttpTrigger(name = "req",
* methods = {HttpMethod.GET},
* authLevel = AuthorizationLevel.ANONYMOUS) Optional&lt;String&gt; dummy,
* {@literal @}CosmosDBInput(name = "database",
* databaseName = "ToDoList",
* collectionName = "Items",
* leaseCollectionName = "",
* id = "{Query.id}"
* connectionStringSetting = "AzureCosmosDBConnection") Optional&lt;String&gt; item,
* final ExecutionContext context
* ) {
* return item.orElse("Not found");
* }</pre>
*
* @since 1.0.0
*/
@Retention(RetentionPolicy.RUNTIME)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,18 @@
* <li>Any POJO type</li>
* </ul>
*
* <p>The following example shows a Java function that adds a document to a database, using data provided in message from
* Queue storage.</p>
*
* <pre>{@literal @}FunctionName("getItem")
*{@literal @}CosmosDBOutput(name = "database", databaseName = "ToDoList", collectionName = "Items", connectionStringSetting = "AzureCosmosDBConnection")
* public String cosmosDbQueryById(
* {@literal @}QueueTrigger(name = "msg", queueName = "myqueue-items", connection = "AzureWebJobsStorage") String message,
* final ExecutionContext context
* ) {
* return "{ id: " + System.currentTimeMillis() + ", Description: " + message + " }";
* }</pre>
*
* @since 1.0.0
*/
@Retention(RetentionPolicy.RUNTIME)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,20 @@
* <li>Any POJO type</li>
* </ul>
*
* <p>The following example shows a cosmos db trigger which logs the count of the returned items:</p>
* <p>The following example shows a Java function that is invoked when there are inserts or updates in the specified
* database and collection.</p>
*
* <pre>{@literal @}FunctionName("cdbprocessor")
* public void cosmosDbProcessor(
* {@literal @}CosmosDBTrigger(name = "items",
* databaseName = "mydbname",
* collectionName = "mycollname",
* leaseCollectionName = "",
* connectionStringSetting = "myconnvarname") MyDataItem[] items,
* <pre>{@literal @}FunctionName("cosmosDBMonitor")
* public void cosmosDbLog(
* {@literal @}CosmosDBTrigger(name = "database",
* databaseName = "ToDoList",
* collectionName = "Items",
* leaseCollectionName = "leases",
* createLeaseCollectionIfNotExists = true,
* connectionStringSetting = "AzureCosmosDBConnection") String[] items,
* final ExecutionContext context
* ) {
* context.getLogger().info(items.length);
* context.getLogger().info(items.length + "item(s) is/are changed.");
* }</pre>
*
* @since 1.0.0
Expand Down

0 comments on commit 546e322

Please sign in to comment.