Skip to content

Commit

Permalink
Add remaining samples P1 bindings/triggers (#40)
Browse files Browse the repository at this point in the history
* Add CosmosDB binding samples (#34).

* Add EventGrid binding samples (#36).

* Adjust CosmosDB sample according to the feedback

* Fix syntax error in the sample code of CosmosDBInput.

* Modify the samples to match the latest CosmosDB runtime.
  • Loading branch information
Junyi Yi authored and pragnagopa committed Oct 13, 2018
1 parent 68bf858 commit 1f7037f
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,30 @@
* The parameter type can be one of the following:</p>
*
* <ul>
* <li>Any native Java types such as int, String, byte[]</li>
* <li>Some native Java types such as String</li>
* <li>Nullable values using Optional&lt;T&gt;</li>
* <li>Any POJO type</li>
* </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. A sample URL would be like: http://localhost:7071/api/getItem?id=myid.</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",
* id = "{Query.id}",
* connectionStringSetting = "AzureCosmosDBConnection") Optional&lt;String&gt; item
* ) {
* 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 @@ -16,11 +16,20 @@
* The parameter type should be OutputBinding&lt;T&gt;, where T could be one of:</p>
*
* <ul>
* <li>Any native Java types such as int, String, byte[]</li>
* <li>Some native Java types such as String</li>
* <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 the body of an HTTP Post request.</p>
*
* <pre>{@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 + "\" }";
* }</pre>
*
* @since 1.0.0
*/
@Retention(RetentionPolicy.RUNTIME)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,28 @@
* data is changed. The parameter type can be one of the following:</p>
*
* <ul>
* <li>Any native Java types such as int, String, byte[]</li>
* <li>Some native Java types such as String</li>
* <li>Nullable values using Optional&lt;T&gt;</li>
* <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") List&lt;Map&lt;String, String&gt;&gt; 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"));
* }
* }</pre>
*
* @since 1.0.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@
* <li>Any POJO type</li>
* </ul>
*
* <p>The following example shows an event grid trigger which prints out the object:</p>
* <p>The following example shows a Java function that prints out an event:</p>
*
* <pre>{@literal @}FunctionName("egprocessor")
* public void eventGridProcessor(
* {@literal @}EventGridTrigger(name = "obj") MyModel obj,
* <pre>{@literal @}FunctionName("eventGridMonitor")
* public void logEvent(
* {@literal @}EventGridTrigger(name = "event") String content,
* final ExecutionContext context
* ) {
* context.getLogger().info(obj.toString());
* context.getLogger().info(content);
* }</pre>
*
* @since 1.0.0
Expand Down

0 comments on commit 1f7037f

Please sign in to comment.