Skip to content

Commit 4fc74f2

Browse files
committed
Work on service bus output.
1 parent b87d984 commit 4fc74f2

File tree

2 files changed

+63
-2
lines changed

2 files changed

+63
-2
lines changed

articles/azure-functions/functions-bindings-service-bus-output.md

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title: Azure Service Bus output bindings for Azure Functions
33
description: Learn to send Azure Service Bus messages from Azure Functions.
44
ms.assetid: daedacf0-6546-4355-a65c-50873e74f66b
55
ms.topic: reference
6-
ms.date: 03/04/2022
6+
ms.date: 03/06/2023
77
ms.devlang: csharp, java, javascript, powershell, python
88
ms.custom: devx-track-csharp, devx-track-python, ignite-2022
99
zone_pivot_groups: programming-languages-set-functions-lang-workers
@@ -15,6 +15,23 @@ Use Azure Service Bus output binding to send queue or topic messages.
1515

1616
For information on setup and configuration details, see the [overview](functions-bindings-service-bus.md).
1717

18+
::: zone pivot="programming-language-python"
19+
Azure Functions supports two programming models for Python. The way that you define your bindings depends on your chosen programming model.
20+
21+
# [v2](#tab/python-v2)
22+
The Python v2 programming model lets you define bindings using decorators directly in your Python function code. For more information, see the [Python developer guide](functions-reference-python.md?pivots=python-mode-decorators#programming-model).
23+
24+
# [v1](#tab/python-v1)
25+
The Python v1 programming model requires you to define bindings in a separate *function.json* file in the function folder. For more information, see the [Python developer guide](functions-reference-python.md?pivots=python-mode-configuration#programming-model).
26+
27+
---
28+
29+
This article supports both programming models.
30+
31+
> [!IMPORTANT]
32+
> The Python v2 programming model is currently in preview.
33+
::: zone-end
34+
1835
## Example
1936

2037
::: zone pivot="programming-language-csharp"
@@ -218,6 +235,25 @@ Push-OutputBinding -Name outputSbMsg -Value @{
218235

219236
The following example demonstrates how to write out to a Service Bus queue in Python.
220237

238+
# [v2](#tab/python-v2)
239+
240+
```python
241+
import logging
242+
import azure.functions as func
243+
app = func.FunctionApp()
244+
@app.route(route="put_message")
245+
@app.service_bus_topic_output(
246+
arg_name="message",
247+
connection="CONNECTION_SETTING",
248+
topic_name="mytopic")
249+
def main(req: func.HttpRequest, message: func.Out[str]) -> func.HttpResponse:
250+
input_msg = req.params.get('message')
251+
message.set(input_msg)
252+
return 'OK'
253+
```
254+
255+
# [v1](#tab/python-v1)
256+
221257
A Service Bus binding definition is defined in *function.json* where *type* is set to `serviceBus`.
222258

223259
```json
@@ -340,6 +376,24 @@ C# script uses a *function.json* file for configuration instead of attributes. T
340376
---
341377

342378
::: zone-end
379+
380+
::: zone pivot="programming-language-python"
381+
## Decorators
382+
383+
_Applies only to the Python v2 programming model._
384+
385+
For Python v2 functions defined using a decorator, the following properties on the `service_bus_topic_output`:
386+
387+
| Property | Description |
388+
|-------------|-----------------------------|
389+
| `arg_name` | The name of the variable that represents the queue or topic message in function code. |
390+
| `queue_name` | Name of the queue. Set only if sending queue messages, not for a topic. |
391+
| `topic_name` | Name of the topic. Set only if sending topic messages, not for a queue. |
392+
| `connection` | The name of an app setting or setting collection that specifies how to connect to Service Bus. See [Connections](#connections). |
393+
394+
For Python functions defined by using *function.json*, see the [Configuration](#configuration) section.
395+
::: zone-end
396+
343397
::: zone pivot="programming-language-java"
344398
## Annotations
345399

@@ -350,6 +404,13 @@ The `ServiceBusQueueOutput` and `ServiceBusTopicOutput` annotations are availabl
350404
::: zone-end
351405
::: zone pivot="programming-language-javascript,programming-language-powershell,programming-language-python"
352406
## Configuration
407+
::: zone-end
408+
409+
::: zone pivot="programming-language-python"
410+
_Applies only to the Python v1 programming model._
411+
412+
::: zone-end
413+
::: zone pivot="programming-language-javascript,programming-language-powershell,programming-language-python"
353414

354415
The following table explains the binding configuration properties that you set in the *function.json* file and the `ServiceBus` attribute.
355416

articles/azure-functions/functions-bindings-service-bus-trigger.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ C# script uses a *function.json* file for configuration instead of attributes. T
333333

334334
_Applies only to the Python v2 programming model._
335335

336-
For Python v2 functions defined using a decorator, the following properties on the `queue_output`:
336+
For Python v2 functions defined using a decorator, the following properties on the `service_bus_queue_trigger`:
337337

338338
| Property | Description |
339339
|-------------|-----------------------------|

0 commit comments

Comments
 (0)