Skip to content
This repository was archived by the owner on Oct 14, 2023. It is now read-only.
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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-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)
Expand Down
7 changes: 7 additions & 0 deletions v2functions/sbqueue-trigger-sbqueue-out-binding/__init.py__
Original file line number Diff line number Diff line change
@@ -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)
19 changes: 19 additions & 0 deletions v2functions/sbqueue-trigger-sbqueue-out-binding/function.json
Original file line number Diff line number Diff line change
@@ -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"
}
]
}
71 changes: 71 additions & 0 deletions v2functions/sbqueue-trigger-sbqueue-out-binding/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# sbqueue-trigger-sbqueue-out-binding (Python)

| Sample | Description | Trigger | In Bindings | Out Bindings
| ------------- | ------------- | ------------- | ----------- | ----------- |
| `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

`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
```