From 278696f3752c5fce7d14c1f9bc4dd4b44f8babbc Mon Sep 17 00:00:00 2001 From: Junyi Yi Date: Thu, 3 May 2018 19:32:06 -0400 Subject: [PATCH] Add sample code to all triggers. (#99) --- .../functions/annotation/BlobTrigger.java | 14 ++++++++++++++ .../functions/annotation/CosmosDBTrigger.java | 13 +++++++++++++ .../functions/annotation/EventGridTrigger.java | 13 +++++++++++++ .../functions/annotation/EventHubTrigger.java | 11 +++++++++++ .../functions/annotation/QueueTrigger.java | 11 +++++++++++ .../annotation/ServiceBusQueueTrigger.java | 15 +++++++++++++++ .../annotation/ServiceBusTopicTrigger.java | 12 ++++++++++++ .../functions/annotation/TableInput.java | 15 +++++++++++++++ 8 files changed, 104 insertions(+) diff --git a/azure-functions-java-core/src/main/java/com/microsoft/azure/serverless/functions/annotation/BlobTrigger.java b/azure-functions-java-core/src/main/java/com/microsoft/azure/serverless/functions/annotation/BlobTrigger.java index 23355c2..df63304 100644 --- a/azure-functions-java-core/src/main/java/com/microsoft/azure/serverless/functions/annotation/BlobTrigger.java +++ b/azure-functions-java-core/src/main/java/com/microsoft/azure/serverless/functions/annotation/BlobTrigger.java @@ -12,7 +12,21 @@ import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; /** + *

The following example shows a storage blob trigger which logs the blob filename as well as its size:

* + *
{@literal @}FunctionName("blobprocessor")
+ * public void run(
+ *    {@literal @}BlobTrigger(name = "file",
+ *                  dataType = "binary",
+ *                  path = "myblob/filepath",
+ *                  connection = "myconnvarname") byte[] content,
+ *    {@literal @}BindingName("name") String filename,
+ *     final ExecutionContext context
+ * ) {
+ *     context.getLogger().info("Name: " + name + " Size: " + content.length + " bytes");
+ * }
+ * + * @see com.microsoft.azure.serverless.functions.annotation.BindingName * @since 1.0.0 */ @Retention(RetentionPolicy.RUNTIME) diff --git a/azure-functions-java-core/src/main/java/com/microsoft/azure/serverless/functions/annotation/CosmosDBTrigger.java b/azure-functions-java-core/src/main/java/com/microsoft/azure/serverless/functions/annotation/CosmosDBTrigger.java index f85d507..617c39e 100644 --- a/azure-functions-java-core/src/main/java/com/microsoft/azure/serverless/functions/annotation/CosmosDBTrigger.java +++ b/azure-functions-java-core/src/main/java/com/microsoft/azure/serverless/functions/annotation/CosmosDBTrigger.java @@ -12,6 +12,19 @@ import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; /** + *

The following example shows a cosmos db trigger which logs the count of the returned items:

+ * + *
{@literal @}FunctionName("cdbprocessor")
+ * public void cosmosDbProcessor(
+ *    {@literal @}CosmosDBTrigger(name = "items",
+ *                      databaseName = "mydbname",
+ *                      collectionName = "mycollname",
+ *                      leaseCollectionName = "",
+ *                      connectionStringSetting = "myconnvarname") MyDataItem[] items,
+ *     final ExecutionContext context
+ * ) {
+ *     context.getLogger().info(items.length);
+ * }
* * @since 1.0.0 */ diff --git a/azure-functions-java-core/src/main/java/com/microsoft/azure/serverless/functions/annotation/EventGridTrigger.java b/azure-functions-java-core/src/main/java/com/microsoft/azure/serverless/functions/annotation/EventGridTrigger.java index e50baca..b0c435f 100644 --- a/azure-functions-java-core/src/main/java/com/microsoft/azure/serverless/functions/annotation/EventGridTrigger.java +++ b/azure-functions-java-core/src/main/java/com/microsoft/azure/serverless/functions/annotation/EventGridTrigger.java @@ -11,6 +11,19 @@ import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; +/** + *

The following example shows an event grid trigger which prints out the object:

+ * + *
{@literal @}FunctionName("egprocessor")
+ * public void eventGridProcessor(
+ *    {@literal @}EventGridTrigger(name = "obj") MyModel obj,
+ *     final ExecutionContext context
+ * ) {
+ *     context.getLogger().info(obj.toString());
+ * }
+ * + * @since 1.0.0 + */ @Retention(RetentionPolicy.RUNTIME) @Target({ElementType.PARAMETER}) public @interface EventGridTrigger { diff --git a/azure-functions-java-core/src/main/java/com/microsoft/azure/serverless/functions/annotation/EventHubTrigger.java b/azure-functions-java-core/src/main/java/com/microsoft/azure/serverless/functions/annotation/EventHubTrigger.java index c2481a7..b98bf65 100644 --- a/azure-functions-java-core/src/main/java/com/microsoft/azure/serverless/functions/annotation/EventHubTrigger.java +++ b/azure-functions-java-core/src/main/java/com/microsoft/azure/serverless/functions/annotation/EventHubTrigger.java @@ -12,6 +12,17 @@ import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; /** + *

The following example shows an event hub trigger which logs the message:

+ * + *
{@literal @}FunctionName("ehprocessor")
+ * public void eventHubProcessor(
+ *    {@literal @}EventHubTrigger(name = "msg",
+ *                      eventHubName = "myeventhubname",
+ *                      connection = "myconnvarname") String message,
+ *     final ExecutionContext context
+ * ) {
+ *     context.getLogger().info(message);
+ * }
* * @since 1.0.0 */ diff --git a/azure-functions-java-core/src/main/java/com/microsoft/azure/serverless/functions/annotation/QueueTrigger.java b/azure-functions-java-core/src/main/java/com/microsoft/azure/serverless/functions/annotation/QueueTrigger.java index b80c88e..e8d5d03 100644 --- a/azure-functions-java-core/src/main/java/com/microsoft/azure/serverless/functions/annotation/QueueTrigger.java +++ b/azure-functions-java-core/src/main/java/com/microsoft/azure/serverless/functions/annotation/QueueTrigger.java @@ -12,6 +12,17 @@ import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; /** + *

The following example shows a storage queue trigger which logs the message:

+ * + *
{@literal @}FunctionName("queueprocessor")
+ * public void run(
+ *    {@literal @}QueueTrigger(name = "msg",
+ *                   queueName = "myqueuename",
+ *                   connection = "myconnvarname") String message,
+ *     final ExecutionContext context
+ * ) {
+ *     context.getLogger().info(message);
+ * }
* * @since 1.0.0 */ diff --git a/azure-functions-java-core/src/main/java/com/microsoft/azure/serverless/functions/annotation/ServiceBusQueueTrigger.java b/azure-functions-java-core/src/main/java/com/microsoft/azure/serverless/functions/annotation/ServiceBusQueueTrigger.java index 57d8dfe..d22d5f4 100644 --- a/azure-functions-java-core/src/main/java/com/microsoft/azure/serverless/functions/annotation/ServiceBusQueueTrigger.java +++ b/azure-functions-java-core/src/main/java/com/microsoft/azure/serverless/functions/annotation/ServiceBusQueueTrigger.java @@ -12,6 +12,21 @@ import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; /** + *

Use ServiceBusQueueTrigger annotation to respond to messages from a Service Bus queue. Similar to other annotations, + * ServiceBusQueueTrigger could be applied to a method parameter with any type (including String, int or any POJO) as long + * as the parameter is JSON-deserializable.

+ * + *

The following example shows a service bus queue trigger which logs the queue message:

+ * + *
{@literal @}FunctionName("sbprocessor")
+ * public void serviceBusProcess(
+ *    {@literal @}ServiceBusQueueTrigger(name = "msg",
+ *                             queueName = "myqueuename",
+ *                             connection = "myconnvarname") String message,
+ *     final ExecutionContext context
+ * ) {
+ *     context.getLogger().info(message);
+ * }
* * @since 1.0.0 */ diff --git a/azure-functions-java-core/src/main/java/com/microsoft/azure/serverless/functions/annotation/ServiceBusTopicTrigger.java b/azure-functions-java-core/src/main/java/com/microsoft/azure/serverless/functions/annotation/ServiceBusTopicTrigger.java index 3dbd989..2382005 100644 --- a/azure-functions-java-core/src/main/java/com/microsoft/azure/serverless/functions/annotation/ServiceBusTopicTrigger.java +++ b/azure-functions-java-core/src/main/java/com/microsoft/azure/serverless/functions/annotation/ServiceBusTopicTrigger.java @@ -12,6 +12,18 @@ import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; /** + *

The following example shows a service bus topic trigger which logs the message:

+ * + *
{@literal @}FunctionName("sbprocessor")
+ * public void serviceBusProcess(
+ *    {@literal @}ServiceBusTopicTrigger(name = "msg",
+ *                             topicName = "mytopicname",
+ *                             subscriptionName = "mysubname",
+ *                             connection = "myconnvarname") String message,
+ *     final ExecutionContext context
+ * ) {
+ *     context.getLogger().info(message);
+ * }
* * @since 1.0.0 */ diff --git a/azure-functions-java-core/src/main/java/com/microsoft/azure/serverless/functions/annotation/TableInput.java b/azure-functions-java-core/src/main/java/com/microsoft/azure/serverless/functions/annotation/TableInput.java index e97fc06..b1fc3fb 100644 --- a/azure-functions-java-core/src/main/java/com/microsoft/azure/serverless/functions/annotation/TableInput.java +++ b/azure-functions-java-core/src/main/java/com/microsoft/azure/serverless/functions/annotation/TableInput.java @@ -12,7 +12,22 @@ import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; /** + *

The following example shows an HTTP trigger which returned the total count of the items in a table storage:

* + *
{@literal @}FunctionName("getallcount")
+ * public int run(
+ *    {@literal @}HttpTrigger(name = "req",
+ *                  methods = {"get"},
+ *                  authLevel = AuthorizationLevel.ANONYMOUS) Object dummyShouldNotBeUsed,
+ *    {@literal @}TableInput(name = "items",
+ *                 tableName = "mytablename",
+ *                 partitionKey = "myparkey",
+ *                 connection = "myconnvarname") MyItem[] items
+ * ) {
+ *     return items.length;
+ * }
+ * + * @see com.microsoft.azure.serverless.functions.annotation.HttpTrigger * @since 1.0.0 */ @Retention(RetentionPolicy.RUNTIME)