Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the Azure Functions BBEs #4398

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions examples/azure-functions-cosmosdb-trigger/az_deploy.out
Original file line number Diff line number Diff line change
@@ -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]
Original file line number Diff line number Diff line change
@@ -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();
}
}
Original file line number Diff line number Diff line change
@@ -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 `<function_app_name>`).
::: 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/).
14 changes: 14 additions & 0 deletions examples/azure-functions-cosmosdb-trigger/bal_build.out
Original file line number Diff line number Diff line change
@@ -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 <function_app_name> --script-root target/azure_functions

target/bin/azure_functions_deployment.jar
1 change: 1 addition & 0 deletions examples/azure-functions-cosmosdb-trigger/bal_new.out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
$ bal new azure-functions-cosmosdb-trigger
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
$ curl https://bal-bbe.azurewebsites.net/hello\?name\=Jack
Hello, Jack!
Original file line number Diff line number Diff line change
@@ -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.

Expand Down
12 changes: 12 additions & 0 deletions examples/azure-functions-http-trigger/az_deploy.out
Original file line number Diff line number Diff line change
@@ -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]
Original file line number Diff line number Diff line change
@@ -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 `<function_app_name>`).
::: 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/).
Original file line number Diff line number Diff line change
@@ -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();
}
}
14 changes: 14 additions & 0 deletions examples/azure-functions-http-trigger/bal_build.out
Original file line number Diff line number Diff line change
@@ -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 <function_app_name> --script-root target/azure_functions

target/bin/azure_functions_deployment.jar
1 change: 1 addition & 0 deletions examples/azure-functions-http-trigger/bal_new.out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
$ bal new azure-functions-timer-trigger
2 changes: 2 additions & 0 deletions examples/azure-functions-http-trigger/execute_function.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
$ curl https://bal-bbe.azurewebsites.net/hello\?name\=Jack
Hello, Jack!
12 changes: 12 additions & 0 deletions examples/azure-functions-native/az_deploy.out
Original file line number Diff line number Diff line change
@@ -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]
19 changes: 19 additions & 0 deletions examples/azure-functions-native/azure-functions-hello-world.bal
Original file line number Diff line number Diff line change
@@ -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();
}
}
21 changes: 21 additions & 0 deletions examples/azure-functions-native/azure-functions-hello-world.md
Original file line number Diff line number Diff line change
@@ -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 `<function_app_name>`).
::: 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/).
14 changes: 14 additions & 0 deletions examples/azure-functions-native/bal_build.out
Original file line number Diff line number Diff line change
@@ -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 <function_app_name> --script-root target/azure_functions

target/bin/azure_functions_deployment.jar
1 change: 1 addition & 0 deletions examples/azure-functions-native/bal_new.out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
$ bal new azure-functions-native
2 changes: 2 additions & 0 deletions examples/azure-functions-native/execute_function.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
$ curl https://bal-bbe.azurewebsites.net/hello\?name\=Jack
Hello, Jack!
12 changes: 12 additions & 0 deletions examples/azure-functions-timer-trigger/az_deploy.out
Original file line number Diff line number Diff line change
@@ -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]
Original file line number Diff line number Diff line change
@@ -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();
}
}
Original file line number Diff line number Diff line change
@@ -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 `<function_app_name>`).
::: 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/).
14 changes: 14 additions & 0 deletions examples/azure-functions-timer-trigger/bal_build.out
Original file line number Diff line number Diff line change
@@ -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 <function_app_name> --script-root target/azure_functions

target/bin/azure_functions_deployment.jar
1 change: 1 addition & 0 deletions examples/azure-functions-timer-trigger/bal_new.out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
$ bal new azure-functions-http-trigger
2 changes: 2 additions & 0 deletions examples/azure-functions-timer-trigger/execute_function.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
$ curl https://bal-bbe.azurewebsites.net/hello\?name\=Jack
Hello, Jack!
36 changes: 36 additions & 0 deletions examples/index.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
]
}
Expand Down