Skip to content
This repository was archived by the owner on Oct 14, 2023. It is now read-only.

Commit 5126220

Browse files
authored
Merge pull request #26 from snobu/master
Added Service Bus Queue sample for trigger and output
2 parents 94d010f + 0a9afc0 commit 5126220

File tree

4 files changed

+98
-0
lines changed

4 files changed

+98
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ This is a collection of Python function samples on Azure Functions 2.X. For a co
2626
| [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 |
2727
| [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 |
2828
| [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 |
29+
| [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 |
2930

3031
### Documents
3132
* [Quickstart V2 Python Functions with Azure Functions Core Tools](docs/quickstart-v2-python-functions.md)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import logging
2+
import azure.functions as func
3+
4+
def main(msgIn: func.ServiceBusMessage, msgOut: func.Out[str]):
5+
body = msgIn.get_body().decode('utf-8')
6+
logging.info(f'Processed Service Bus Queue message: {body}')
7+
msgOut.set(msgbody)
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"scriptFile": "__init__.py",
3+
"bindings": [
4+
{
5+
"name": "msgIn",
6+
"type": "serviceBusTrigger",
7+
"direction": "in",
8+
"queueName": "inqueue",
9+
"connection": "ServiceBusNamespaceConnectionString"
10+
},
11+
{
12+
"name": "msgOut",
13+
"type": "serviceBus",
14+
"direction": "out",
15+
"connection": "ServiceBusNamespaceConnectionString",
16+
"queueName": "outqueue"
17+
}
18+
]
19+
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# sbqueue-trigger-sbqueue-out-binding (Python)
2+
3+
| Sample | Description | Trigger | In Bindings | Out Bindings
4+
| ------------- | ------------- | ------------- | ----------- | ----------- |
5+
| `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 |
6+
7+
## Configurations
8+
9+
`function.json`:
10+
11+
```json
12+
{
13+
"scriptFile": "__init__.py",
14+
"bindings": [
15+
{
16+
"name": "msgIn",
17+
"type": "serviceBusTrigger",
18+
"direction": "in",
19+
"queueName": "inqueue",
20+
"connection": "ServiceBusNamespaceConnectionString"
21+
},
22+
{
23+
"name": "msgOut",
24+
"type": "serviceBus",
25+
"direction": "out",
26+
"connection": "ServiceBusNamespaceConnectionString",
27+
"queueName": "outqueue"
28+
}
29+
]
30+
}
31+
```
32+
33+
### Create the Service Bus Queues
34+
35+
Create two Service Bus Queues in the namespace used in `ServiceBusNamespaceConnectionString`, `inqueue` and `outqueue`:
36+
37+
```sh
38+
az servicebus queue create --name inqueue \
39+
--resource-group $RESOURCE_GROUP \
40+
--namespace-name $SERVICEBUS_NAMESPACE
41+
42+
az servicebus queue create --name outqueue \
43+
--resource-group $RESOURCE_GROUP \
44+
--namespace-name $SERVICEBUS_NAMESPACE
45+
```
46+
47+
## How to develop and publish the functions
48+
49+
### Local development
50+
51+
```sh
52+
func host start
53+
```
54+
55+
### Publish the function to the cloud
56+
57+
Publish the function to the cloud
58+
```sh
59+
FUNCTION_APP_NAME="MyFunctionApp"
60+
func azure functionapp publish $FUNCTION_APP_NAME --build-native-deps --no-bundler
61+
```
62+
63+
Add Functions App Settings
64+
```sh
65+
FUNCTION_STORAGE_CONNECTION="*************"
66+
az webapp config appsettings set \
67+
-n $FUNCTION_APP_NAME \
68+
-g $RESOURCE_GROUP \
69+
--settings \
70+
MyStorageConnectionString=$FUNCTION_STORAGE_CONNECTION
71+
```

0 commit comments

Comments
 (0)