diff --git a/examples/azure-functions-cosmosdb-trigger/az_deploy.out b/examples/azure-functions-cosmosdb-trigger/az_deploy.out new file mode 100644 index 0000000000..968f927b8e --- /dev/null +++ b/examples/azure-functions-cosmosdb-trigger/az_deploy.out @@ -0,0 +1,12 @@ +$ func azure functionapp publish bal-bbe --script-root target/azure_functions +Getting site publishing info... +Creating archive for current directory... +Uploading 28.67 MB [##############################################################################] +Upload completed successfully. +Deployment completed successfully. +Syncing triggers... +Functions in bal-bbe: + get-hello - [httpTrigger] + Invoke url: https://bal-bbe.azurewebsites.net/hello + + timer - [timerTrigger] diff --git a/examples/azure-functions-cosmosdb-trigger/azure-functions-cosmosdb-trigger.bal b/examples/azure-functions-cosmosdb-trigger/azure-functions-cosmosdb-trigger.bal new file mode 100644 index 0000000000..0c961713d3 --- /dev/null +++ b/examples/azure-functions-cosmosdb-trigger/azure-functions-cosmosdb-trigger.bal @@ -0,0 +1,19 @@ +import ballerinax/azure_functions as af; + +// This function gets triggered by an HTTP call with the name query parameter and returns a processed HTTP output to the caller. +service / on new af:HttpListener() { + resource function azure-functions-cosmosdb-trigger(string name) returns string { + return "Hello, " + name + "!"; + } +} + +// This function gets executed every 10 seconds by the Azure Functions app. Once the function is executed, the timer +// details will be stored in the selected queue storage for every invocation. +@af:TimerTrigger {schedule: "*/10 * * * * *"} +listener af:TimerListener timerListener = new af:TimerListener(); + +service "timer" on timerListener { + remote function onTrigger(af:TimerMetadata metadata) returns @af:QueueOutput {queueName: "queue3"} string|error { + return "Message Status, " + metadata.IsPastDue.toString(); + } +} diff --git a/examples/azure-functions-cosmosdb-trigger/azure-functions-cosmosdb-trigger.md b/examples/azure-functions-cosmosdb-trigger/azure-functions-cosmosdb-trigger.md new file mode 100644 index 0000000000..f87cc9b194 --- /dev/null +++ b/examples/azure-functions-cosmosdb-trigger/azure-functions-cosmosdb-trigger.md @@ -0,0 +1,21 @@ +# Azure Functions Cosmos DB trigger + +Azure Functions is an event driven, serverless computing platform. Azure Functions can be written from Ballerina using the listeners and services provided by Azure Functions package. You can view the code examples below. + +For more information, see the [Azure deployment guide](/learn/run-in-the-cloud/function-as-a-service/azure-functions/). + +::: code azure-functions-cosmosdb-trigger.bal ::: + +Create a Ballerina package and replace the content of the generated BAL file with the content above. +::: out bal_new.out ::: + +Build the Ballerina program to generate the Azure Functions artifacts. +::: out bal_build.out ::: + +Execute the Azure CLI command given by the compiler to publish the functions (replace the sample app name given in the command with your respective Azure ``). +::: out az_deploy.out ::: + +Invoke the `HTTP Trigger` functions. +::: out execute_function.out ::: + +The `timer` function is triggered by the Azure Functions app from a timer. You can check the queue storage to see the output. For more information on the infrastructure, see [Azure Functions deployment](/learn/run-in-the-cloud/function-as-a-service/azure-functions/). diff --git a/examples/azure-functions-cosmosdb-trigger/bal_build.out b/examples/azure-functions-cosmosdb-trigger/bal_build.out new file mode 100644 index 0000000000..eb94c67478 --- /dev/null +++ b/examples/azure-functions-cosmosdb-trigger/bal_build.out @@ -0,0 +1,14 @@ +$ bal build --cloud="azure_functions" +Compiling source + wso2/azure-functions-cosmosdb-trigger:0.1.0 + +Generating executable + @azure_functions:Function: timer, get-hello + + Execute the command below to deploy the function locally. + func start --script-root target/azure_functions --java + + Execute the command below to deploy Ballerina Azure Functions. + func azure functionapp publish --script-root target/azure_functions + + target/bin/azure_functions_deployment.jar diff --git a/examples/azure-functions-cosmosdb-trigger/bal_new.out b/examples/azure-functions-cosmosdb-trigger/bal_new.out new file mode 100644 index 0000000000..e79bf8f658 --- /dev/null +++ b/examples/azure-functions-cosmosdb-trigger/bal_new.out @@ -0,0 +1 @@ +$ bal new azure-functions-cosmosdb-trigger diff --git a/examples/azure-functions-cosmosdb-trigger/execute_function.out b/examples/azure-functions-cosmosdb-trigger/execute_function.out new file mode 100644 index 0000000000..0da4052046 --- /dev/null +++ b/examples/azure-functions-cosmosdb-trigger/execute_function.out @@ -0,0 +1,2 @@ +$ curl https://bal-bbe.azurewebsites.net/hello\?name\=Jack +Hello, Jack! diff --git a/examples/azure-functions-hello-world/azure-functions-hello-world.md b/examples/azure-functions-hello-world/azure-functions-hello-world.md index d41f3a3189..8b71a31cf3 100644 --- a/examples/azure-functions-hello-world/azure-functions-hello-world.md +++ b/examples/azure-functions-hello-world/azure-functions-hello-world.md @@ -1,4 +1,4 @@ -# Azure Functions- Hello world +# Azure Functions - Hello world Azure Functions is an event driven, serverless computing platform. Azure Functions can be written from Ballerina using the listeners and services provided by Azure Functions package. You can view the code examples below. diff --git a/examples/azure-functions-http-trigger/az_deploy.out b/examples/azure-functions-http-trigger/az_deploy.out new file mode 100644 index 0000000000..968f927b8e --- /dev/null +++ b/examples/azure-functions-http-trigger/az_deploy.out @@ -0,0 +1,12 @@ +$ func azure functionapp publish bal-bbe --script-root target/azure_functions +Getting site publishing info... +Creating archive for current directory... +Uploading 28.67 MB [##############################################################################] +Upload completed successfully. +Deployment completed successfully. +Syncing triggers... +Functions in bal-bbe: + get-hello - [httpTrigger] + Invoke url: https://bal-bbe.azurewebsites.net/hello + + timer - [timerTrigger] diff --git a/examples/azure-functions-http-trigger/azure-functions-hello-world.md b/examples/azure-functions-http-trigger/azure-functions-hello-world.md new file mode 100644 index 0000000000..bda3bb0927 --- /dev/null +++ b/examples/azure-functions-http-trigger/azure-functions-hello-world.md @@ -0,0 +1,21 @@ +# Azure Functions- HTTP trigger + +Azure Functions is an event driven, serverless computing platform. Azure Functions can be written from Ballerina using the listeners and services provided by Azure Functions package. You can view the code examples below. + +For more information, see the [Azure deployment guide](/learn/run-in-the-cloud/function-as-a-service/azure-functions/). + +::: code azure-functions-timer-trigger.bal ::: + +Create a Ballerina package and replace the content of the generated BAL file with the content above. +::: out bal_new.out ::: + +Build the Ballerina program to generate the Azure Functions artifacts. +::: out bal_build.out ::: + +Execute the Azure CLI command given by the compiler to publish the functions (replace the sample app name given in the command with your respective Azure ``). +::: out az_deploy.out ::: + +Invoke the `HTTP Trigger` functions. +::: out execute_function.out ::: + +The `timer` function is triggered by the Azure Functions app from a timer. You can check the queue storage to see the output. For more information on the infrastructure, see [Azure Functions deployment](/learn/run-in-the-cloud/function-as-a-service/azure-functions/). diff --git a/examples/azure-functions-http-trigger/azure-functions-http-trigger.bal b/examples/azure-functions-http-trigger/azure-functions-http-trigger.bal new file mode 100644 index 0000000000..5d5a48faa9 --- /dev/null +++ b/examples/azure-functions-http-trigger/azure-functions-http-trigger.bal @@ -0,0 +1,19 @@ +import ballerinax/azure_functions as af; + +// This function gets triggered by an HTTP call with the name query parameter and returns a processed HTTP output to the caller. +service / on new af:HttpListener() { + resource function azure-functions-timer-trigger(string name) returns string { + return "Hello, " + name + "!"; + } +} + +// This function gets executed every 10 seconds by the Azure Functions app. Once the function is executed, the timer +// details will be stored in the selected queue storage for every invocation. +@af:TimerTrigger {schedule: "*/10 * * * * *"} +listener af:TimerListener timerListener = new af:TimerListener(); + +service "timer" on timerListener { + remote function onTrigger(af:TimerMetadata metadata) returns @af:QueueOutput {queueName: "queue3"} string|error { + return "Message Status, " + metadata.IsPastDue.toString(); + } +} diff --git a/examples/azure-functions-http-trigger/bal_build.out b/examples/azure-functions-http-trigger/bal_build.out new file mode 100644 index 0000000000..2680763fc1 --- /dev/null +++ b/examples/azure-functions-http-trigger/bal_build.out @@ -0,0 +1,14 @@ +$ bal build --cloud="azure_functions" +Compiling source + wso2/azure-functions-timer-trigger:0.1.0 + +Generating executable + @azure_functions:Function: timer, get-hello + + Execute the command below to deploy the function locally. + func start --script-root target/azure_functions --java + + Execute the command below to deploy Ballerina Azure Functions. + func azure functionapp publish --script-root target/azure_functions + + target/bin/azure_functions_deployment.jar diff --git a/examples/azure-functions-http-trigger/bal_new.out b/examples/azure-functions-http-trigger/bal_new.out new file mode 100644 index 0000000000..a58faf07b6 --- /dev/null +++ b/examples/azure-functions-http-trigger/bal_new.out @@ -0,0 +1 @@ +$ bal new azure-functions-timer-trigger diff --git a/examples/azure-functions-http-trigger/execute_function.out b/examples/azure-functions-http-trigger/execute_function.out new file mode 100644 index 0000000000..0da4052046 --- /dev/null +++ b/examples/azure-functions-http-trigger/execute_function.out @@ -0,0 +1,2 @@ +$ curl https://bal-bbe.azurewebsites.net/hello\?name\=Jack +Hello, Jack! diff --git a/examples/azure-functions-native/az_deploy.out b/examples/azure-functions-native/az_deploy.out new file mode 100644 index 0000000000..968f927b8e --- /dev/null +++ b/examples/azure-functions-native/az_deploy.out @@ -0,0 +1,12 @@ +$ func azure functionapp publish bal-bbe --script-root target/azure_functions +Getting site publishing info... +Creating archive for current directory... +Uploading 28.67 MB [##############################################################################] +Upload completed successfully. +Deployment completed successfully. +Syncing triggers... +Functions in bal-bbe: + get-hello - [httpTrigger] + Invoke url: https://bal-bbe.azurewebsites.net/hello + + timer - [timerTrigger] diff --git a/examples/azure-functions-native/azure-functions-hello-world.bal b/examples/azure-functions-native/azure-functions-hello-world.bal new file mode 100644 index 0000000000..3716f84bcd --- /dev/null +++ b/examples/azure-functions-native/azure-functions-hello-world.bal @@ -0,0 +1,19 @@ +import ballerinax/azure_functions as af; + +// This function gets triggered by an HTTP call with the name query parameter and returns a processed HTTP output to the caller. +service / on new af:HttpListener() { + resource function azure-functions-native(string name) returns string { + return "Hello, " + name + "!"; + } +} + +// This function gets executed every 10 seconds by the Azure Functions app. Once the function is executed, the timer +// details will be stored in the selected queue storage for every invocation. +@af:TimerTrigger {schedule: "*/10 * * * * *"} +listener af:TimerListener timerListener = new af:TimerListener(); + +service "timer" on timerListener { + remote function onTrigger(af:TimerMetadata metadata) returns @af:QueueOutput {queueName: "queue3"} string|error { + return "Message Status, " + metadata.IsPastDue.toString(); + } +} diff --git a/examples/azure-functions-native/azure-functions-hello-world.md b/examples/azure-functions-native/azure-functions-hello-world.md new file mode 100644 index 0000000000..606aee6694 --- /dev/null +++ b/examples/azure-functions-native/azure-functions-hello-world.md @@ -0,0 +1,21 @@ +# Azure Functions native + +Azure Functions is an event driven, serverless computing platform. Azure Functions can be written from Ballerina using the listeners and services provided by Azure Functions package. You can view the code examples below. + +For more information, see the [Azure deployment guide](/learn/run-in-the-cloud/function-as-a-service/azure-functions/). + +::: code azure-functions-native.bal ::: + +Create a Ballerina package and replace the content of the generated BAL file with the content above. +::: out bal_new.out ::: + +Build the Ballerina program to generate the Azure Functions artifacts. +::: out bal_build.out ::: + +Execute the Azure CLI command given by the compiler to publish the functions (replace the sample app name given in the command with your respective Azure ``). +::: out az_deploy.out ::: + +Invoke the `HTTP Trigger` functions. +::: out execute_function.out ::: + +The `timer` function is triggered by the Azure Functions app from a timer. You can check the queue storage to see the output. For more information on the infrastructure, see [Azure Functions deployment](/learn/run-in-the-cloud/function-as-a-service/azure-functions/). diff --git a/examples/azure-functions-native/bal_build.out b/examples/azure-functions-native/bal_build.out new file mode 100644 index 0000000000..953a764597 --- /dev/null +++ b/examples/azure-functions-native/bal_build.out @@ -0,0 +1,14 @@ +$ bal build --cloud="azure_functions" +Compiling source + wso2/azure-functions-native:0.1.0 + +Generating executable + @azure_functions:Function: timer, get-hello + + Execute the command below to deploy the function locally. + func start --script-root target/azure_functions --java + + Execute the command below to deploy Ballerina Azure Functions. + func azure functionapp publish --script-root target/azure_functions + + target/bin/azure_functions_deployment.jar diff --git a/examples/azure-functions-native/bal_new.out b/examples/azure-functions-native/bal_new.out new file mode 100644 index 0000000000..a256d15dce --- /dev/null +++ b/examples/azure-functions-native/bal_new.out @@ -0,0 +1 @@ +$ bal new azure-functions-native diff --git a/examples/azure-functions-native/execute_function.out b/examples/azure-functions-native/execute_function.out new file mode 100644 index 0000000000..0da4052046 --- /dev/null +++ b/examples/azure-functions-native/execute_function.out @@ -0,0 +1,2 @@ +$ curl https://bal-bbe.azurewebsites.net/hello\?name\=Jack +Hello, Jack! diff --git a/examples/azure-functions-timer-trigger/az_deploy.out b/examples/azure-functions-timer-trigger/az_deploy.out new file mode 100644 index 0000000000..968f927b8e --- /dev/null +++ b/examples/azure-functions-timer-trigger/az_deploy.out @@ -0,0 +1,12 @@ +$ func azure functionapp publish bal-bbe --script-root target/azure_functions +Getting site publishing info... +Creating archive for current directory... +Uploading 28.67 MB [##############################################################################] +Upload completed successfully. +Deployment completed successfully. +Syncing triggers... +Functions in bal-bbe: + get-hello - [httpTrigger] + Invoke url: https://bal-bbe.azurewebsites.net/hello + + timer - [timerTrigger] diff --git a/examples/azure-functions-timer-trigger/azure-functions-timer-trigger.bal b/examples/azure-functions-timer-trigger/azure-functions-timer-trigger.bal new file mode 100644 index 0000000000..f90074aa51 --- /dev/null +++ b/examples/azure-functions-timer-trigger/azure-functions-timer-trigger.bal @@ -0,0 +1,19 @@ +import ballerinax/azure_functions as af; + +// This function gets triggered by an HTTP call with the name query parameter and returns a processed HTTP output to the caller. +service / on new af:HttpListener() { + resource function azure-functions-http-trigger(string name) returns string { + return "Hello, " + name + "!"; + } +} + +// This function gets executed every 10 seconds by the Azure Functions app. Once the function is executed, the timer +// details will be stored in the selected queue storage for every invocation. +@af:TimerTrigger {schedule: "*/10 * * * * *"} +listener af:TimerListener timerListener = new af:TimerListener(); + +service "timer" on timerListener { + remote function onTrigger(af:TimerMetadata metadata) returns @af:QueueOutput {queueName: "queue3"} string|error { + return "Message Status, " + metadata.IsPastDue.toString(); + } +} diff --git a/examples/azure-functions-timer-trigger/azure-functions-timer-trigger.md b/examples/azure-functions-timer-trigger/azure-functions-timer-trigger.md new file mode 100644 index 0000000000..a5c889f620 --- /dev/null +++ b/examples/azure-functions-timer-trigger/azure-functions-timer-trigger.md @@ -0,0 +1,21 @@ +# Azure Functions timer trigger + +Azure Functions is an event driven, serverless computing platform. Azure Functions can be written from Ballerina using the listeners and services provided by Azure Functions package. You can view the code examples below. + +For more information, see the [Azure deployment guide](/learn/run-in-the-cloud/function-as-a-service/azure-functions/). + +::: code azure-functions-http-trigger.bal ::: + +Create a Ballerina package and replace the content of the generated BAL file with the content above. +::: out bal_new.out ::: + +Build the Ballerina program to generate the Azure Functions artifacts. +::: out bal_build.out ::: + +Execute the Azure CLI command given by the compiler to publish the functions (replace the sample app name given in the command with your respective Azure ``). +::: out az_deploy.out ::: + +Invoke the `HTTP Trigger` functions. +::: out execute_function.out ::: + +The `timer` function is triggered by the Azure Functions app from a timer. You can check the queue storage to see the output. For more information on the infrastructure, see [Azure Functions deployment](/learn/run-in-the-cloud/function-as-a-service/azure-functions/). diff --git a/examples/azure-functions-timer-trigger/bal_build.out b/examples/azure-functions-timer-trigger/bal_build.out new file mode 100644 index 0000000000..a27fbffaf3 --- /dev/null +++ b/examples/azure-functions-timer-trigger/bal_build.out @@ -0,0 +1,14 @@ +$ bal build --cloud="azure_functions" +Compiling source + wso2/azure-functions-http-trigger:0.1.0 + +Generating executable + @azure_functions:Function: timer, get-hello + + Execute the command below to deploy the function locally. + func start --script-root target/azure_functions --java + + Execute the command below to deploy Ballerina Azure Functions. + func azure functionapp publish --script-root target/azure_functions + + target/bin/azure_functions_deployment.jar diff --git a/examples/azure-functions-timer-trigger/bal_new.out b/examples/azure-functions-timer-trigger/bal_new.out new file mode 100644 index 0000000000..c358b8cb28 --- /dev/null +++ b/examples/azure-functions-timer-trigger/bal_new.out @@ -0,0 +1 @@ +$ bal new azure-functions-http-trigger diff --git a/examples/azure-functions-timer-trigger/execute_function.out b/examples/azure-functions-timer-trigger/execute_function.out new file mode 100644 index 0000000000..0da4052046 --- /dev/null +++ b/examples/azure-functions-timer-trigger/execute_function.out @@ -0,0 +1,2 @@ +$ curl https://bal-bbe.azurewebsites.net/hello\?name\=Jack +Hello, Jack! diff --git a/examples/index.json b/examples/index.json index e0a18e8717..31724e25f7 100644 --- a/examples/index.json +++ b/examples/index.json @@ -4400,6 +4400,42 @@ "disableVerificationReason": "Needs prerequisite condition", "disablePlayground": true, "isLearnByExample": false + }, + { + "name": "Timer trigger", + "url": "azure-functions-timer-trigger", + "verifyBuild": false, + "verifyOutput": false, + "disableVerificationReason": "Needs prerequisite condition", + "disablePlayground": true, + "isLearnByExample": false + }, + { + "name": "HTTP trigger", + "url": "azure-functions-http-trigger", + "verifyBuild": false, + "verifyOutput": false, + "disableVerificationReason": "Needs prerequisite condition", + "disablePlayground": true, + "isLearnByExample": false + }, + { + "name": "HTTP trigger", + "url": "azure-functions-cosmosdb-trigger", + "verifyBuild": false, + "verifyOutput": false, + "disableVerificationReason": "Needs prerequisite condition", + "disablePlayground": true, + "isLearnByExample": false + }, + { + "name": "HTTP trigger", + "url": "azure-functions-native", + "verifyBuild": false, + "verifyOutput": false, + "disableVerificationReason": "Needs prerequisite condition", + "disablePlayground": true, + "isLearnByExample": false } ] }