From 1068d75c6984e5b7fa477e72d62dc5fdc94e62a9 Mon Sep 17 00:00:00 2001 From: snobu Date: Sat, 3 Aug 2019 17:23:34 +0300 Subject: [PATCH 1/2] Added Service Bus Queue sample for trigger and output --- README.md | 1 + .../__init.py__ | 7 ++ .../function.json | 19 +++++ .../readme.md | 71 +++++++++++++++++++ 4 files changed, 98 insertions(+) create mode 100644 v2functions/sbqueue-trigger-sbqueue-out-binding/__init.py__ create mode 100644 v2functions/sbqueue-trigger-sbqueue-out-binding/function.json create mode 100644 v2functions/sbqueue-trigger-sbqueue-out-binding/readme.md diff --git a/README.md b/README.md index 14b845c..76f24bd 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,7 @@ This is a collection of Python function samples on Azure Functions 2.X. For a co | [http-trigger-blob-sas-token](v2functions/http-trigger-blob-sas-token) | Azure Function HTTP Trigger Python Sample that returns a SAS token for Azure Storage for the specified container and blob name | HTTP | NONE | HTTP | | [http-trigger-dump-request](v2functions/http-trigger-dump-request) | Azure Function HTTP Trigger Python Sample that returns request dump info with JSON format | HTTP | NONE | HTTP | | [blob-trigger-watermark-blob-out-binding](v2functions/blob-trigger-watermark-blob-out-binding) | Azure Function Python Sample that watermarks an image. This function triggers on an input blob (image) and adds a watermark by calling into the Pillow library. The resulting composite image is then written back to blob storage using a blob output binding. | Blob Storage | Blob Storage | Blob Storage | +| [sbqueue-trigger-blob-in-out-binding](v2functions/sbqueue-trigger-sbqueue-out-binding) | Azure Functions Service Bus Queue Trigger Python Sample. The function demonstrates reading from a Service Bus queue and placing a message into an output Service Bus queue. | Service Bus Queue | None | Service Bus Queue | ### Documents * [Quickstart V2 Python Functions with Azure Functions Core Tools](docs/quickstart-v2-python-functions.md) diff --git a/v2functions/sbqueue-trigger-sbqueue-out-binding/__init.py__ b/v2functions/sbqueue-trigger-sbqueue-out-binding/__init.py__ new file mode 100644 index 0000000..eb0d26d --- /dev/null +++ b/v2functions/sbqueue-trigger-sbqueue-out-binding/__init.py__ @@ -0,0 +1,7 @@ +import logging +import azure.functions as func + +def main(msgIn: func.ServiceBusMessage, msgOut: func.Out[str]): + body = msgIn.get_body().decode('utf-8') + logging.info(f'Processed Service Bus Queue message: {body}') + msgOut.set(msgbody) \ No newline at end of file diff --git a/v2functions/sbqueue-trigger-sbqueue-out-binding/function.json b/v2functions/sbqueue-trigger-sbqueue-out-binding/function.json new file mode 100644 index 0000000..6cbaf55 --- /dev/null +++ b/v2functions/sbqueue-trigger-sbqueue-out-binding/function.json @@ -0,0 +1,19 @@ +{ + "scriptFile": "__init__.py", + "bindings": [ + { + "name": "msgIn", + "type": "serviceBusTrigger", + "direction": "in", + "queueName": "inqueue", + "connection": "ServiceBusNamespaceConnectionString" + }, + { + "name": "msgOut", + "type": "serviceBus", + "direction": "out", + "connection": "ServiceBusNamespaceConnectionString", + "queueName": "outqueue" + } + ] + } \ No newline at end of file diff --git a/v2functions/sbqueue-trigger-sbqueue-out-binding/readme.md b/v2functions/sbqueue-trigger-sbqueue-out-binding/readme.md new file mode 100644 index 0000000..eadd524 --- /dev/null +++ b/v2functions/sbqueue-trigger-sbqueue-out-binding/readme.md @@ -0,0 +1,71 @@ +# sbqueue-trigger-sbqueue-out-binding (Python) + +| Sample | Description | Trigger | In Bindings | Out Bindings +| ------------- | ------------- | ------------- | ----------- | ----------- | +| `sbqueue-trigger-blob-in-out-binding` | Azure Functions Service Bus Queue Trigger Python Sample. The function demonstrates reading from a Service Bus queue and placing a new message into a Service Bus queue. | Service Bus Queue | None | Service Bus Queue | + +## Configurations + +`function.json`: + +```json +{ + "scriptFile": "__init__.py", + "bindings": [ + { + "name": "msgIn", + "type": "serviceBusTrigger", + "direction": "in", + "queueName": "inqueue", + "connection": "ServiceBusNamespaceConnectionString" + }, + { + "name": "msgOut", + "type": "serviceBus", + "direction": "out", + "connection": "ServiceBusNamespaceConnectionString", + "queueName": "outqueue" + } + ] +} +``` + +### Create the Service Bus Queues + +Create two Service Bus Queues in the namespace used in `ServiceBusNamespaceConnectionString`, `inqueue` and `outqueue`: + +```sh +az servicebus queue create --name inqueue \ + --resource-group $RESOURCE_GROUP \ + --namespace-name $SERVICEBUS_NAMESPACE + +az servicebus queue create --name outqueue \ + --resource-group $RESOURCE_GROUP \ + --namespace-name $SERVICEBUS_NAMESPACE +``` + +## How to develop and publish the functions + +### Local development + +```sh +func host start +``` + +### Publish the function to the cloud + +Publish the function to the cloud +```sh +FUNCTION_APP_NAME="MyFunctionApp" +func azure functionapp publish $FUNCTION_APP_NAME --build-native-deps --no-bundler +``` + +Add Functions App Settings +```sh +FUNCTION_STORAGE_CONNECTION="*************" +az webapp config appsettings set \ + -n $FUNCTION_APP_NAME \ + -g $RESOURCE_GROUP \ + --settings \ + MyStorageConnectionString=$FUNCTION_STORAGE_CONNECTION +``` \ No newline at end of file From 0a9afc0a48d6092808e55e938b4eac7d66a60096 Mon Sep 17 00:00:00 2001 From: snobu Date: Sat, 3 Aug 2019 17:27:07 +0300 Subject: [PATCH 2/2] Fix markdown link for Service Bus sample --- README.md | 2 +- v2functions/sbqueue-trigger-sbqueue-out-binding/readme.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 76f24bd..458a1f8 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ This is a collection of Python function samples on Azure Functions 2.X. For a co | [http-trigger-blob-sas-token](v2functions/http-trigger-blob-sas-token) | Azure Function HTTP Trigger Python Sample that returns a SAS token for Azure Storage for the specified container and blob name | HTTP | NONE | HTTP | | [http-trigger-dump-request](v2functions/http-trigger-dump-request) | Azure Function HTTP Trigger Python Sample that returns request dump info with JSON format | HTTP | NONE | HTTP | | [blob-trigger-watermark-blob-out-binding](v2functions/blob-trigger-watermark-blob-out-binding) | Azure Function Python Sample that watermarks an image. This function triggers on an input blob (image) and adds a watermark by calling into the Pillow library. The resulting composite image is then written back to blob storage using a blob output binding. | Blob Storage | Blob Storage | Blob Storage | -| [sbqueue-trigger-blob-in-out-binding](v2functions/sbqueue-trigger-sbqueue-out-binding) | Azure Functions Service Bus Queue Trigger Python Sample. The function demonstrates reading from a Service Bus queue and placing a message into an output Service Bus queue. | Service Bus Queue | None | Service Bus Queue | +| [sbqueue-trigger-sbqueue-out-binding](v2functions/sbqueue-trigger-sbqueue-out-binding) | Azure Functions Service Bus Queue Trigger Python Sample. The function demonstrates reading from a Service Bus queue and placing a message into an output Service Bus queue. | Service Bus Queue | None | Service Bus Queue | ### Documents * [Quickstart V2 Python Functions with Azure Functions Core Tools](docs/quickstart-v2-python-functions.md) diff --git a/v2functions/sbqueue-trigger-sbqueue-out-binding/readme.md b/v2functions/sbqueue-trigger-sbqueue-out-binding/readme.md index eadd524..32ee076 100644 --- a/v2functions/sbqueue-trigger-sbqueue-out-binding/readme.md +++ b/v2functions/sbqueue-trigger-sbqueue-out-binding/readme.md @@ -2,7 +2,7 @@ | Sample | Description | Trigger | In Bindings | Out Bindings | ------------- | ------------- | ------------- | ----------- | ----------- | -| `sbqueue-trigger-blob-in-out-binding` | Azure Functions Service Bus Queue Trigger Python Sample. The function demonstrates reading from a Service Bus queue and placing a new message into a Service Bus queue. | Service Bus Queue | None | Service Bus Queue | +| `sbqueue-trigger-sbqueue-out-binding` | Azure Functions Service Bus Queue Trigger Python Sample. The function demonstrates reading from a Service Bus queue and placing a new message into a Service Bus queue. | Service Bus Queue | None | Service Bus Queue | ## Configurations