@@ -3,7 +3,7 @@ title: Azure Service Bus output bindings for Azure Functions
3
3
description : Learn to send Azure Service Bus messages from Azure Functions.
4
4
ms.assetid : daedacf0-6546-4355-a65c-50873e74f66b
5
5
ms.topic : reference
6
- ms.date : 03/06/2023
6
+ ms.date : 01/15/2024
7
7
ms.devlang : csharp
8
8
# ms.devlang: csharp, java, javascript, powershell, python
9
9
ms.custom : devx-track-csharp, devx-track-python, ignite-2022, devx-track-extended-java, devx-track-js
@@ -50,11 +50,45 @@ This example shows a [C# function](dotnet-isolated-process-guide.md) that receiv
50
50
51
51
:::code language="csharp" source="~ /azure-functions-dotnet-worker/samples/Extensions/ServiceBus/ServiceBusReceivedMessageFunctions.cs" id="docsnippet_servicebus_readmessage":::
52
52
53
+   ;
54
+ <hr />
55
+
56
+ This example uses an HTTP trigger with an ` OutputType ` object to both send an HTTP response and write the output message.
57
+
58
+ ``` csharp
59
+ [Function (" HttpSendMsg" )]
60
+ public async Task < OutputType > Run ([HttpTrigger (AuthorizationLevel .Function , " get" , " post" )] HttpRequestData req , FunctionContext context )
61
+ {
62
+ _logger .LogInformation ($" C# HTTP trigger function processed a request for {context .InvocationId }." );
63
+
64
+ HttpResponseData response = req .CreateResponse (HttpStatusCode .OK );
65
+ await response .WriteStringAsync (" HTTP response: Message sent" );
66
+
67
+ return new OutputType ()
68
+ {
69
+ OutputEvent = " MyMessage" ,
70
+ HttpResponse = response
71
+ };
72
+ }
73
+ ```
74
+
75
+ This code defines the multiple output type ` OutputType ` , which includes the Service Bus output binding definition on ` OutputEvent ` :
76
+
77
+ ``` csharp
78
+ public class OutputType
79
+ {
80
+ [ServiceBusOutput (" TopicOrQueueName" , Connection = " ServiceBusConnection" )]
81
+ public string OutputEvent { get ; set ; }
82
+
83
+ public HttpResponseData HttpResponse { get ; set ; }
84
+ }
85
+ ```
86
+
53
87
# [ In-process model] ( #tab/in-process )
54
88
55
89
The following example shows a [ C# function] ( functions-dotnet-class-library.md ) that sends a Service Bus queue message:
56
90
57
- ``` cs
91
+ ``` csharp
58
92
[FunctionName (" ServiceBusOutput" )]
59
93
[return : ServiceBus (" myqueue" , Connection = " ServiceBusConnection" )]
60
94
public static string ServiceBusOutput ([HttpTrigger ] dynamic input , ILogger log )
@@ -63,6 +97,28 @@ public static string ServiceBusOutput([HttpTrigger] dynamic input, ILogger log)
63
97
return input .Text ;
64
98
}
65
99
```
100
+   ;
101
+ <hr />
102
+
103
+ Instead of using the return statement to send the message, this HTTP trigger function returns an HTTP response that is different from the output message.
104
+
105
+ ``` csharp
106
+ [FunctionName (" HttpTrigger1" )]
107
+ public static async Task < IActionResult > Run (
108
+ [HttpTrigger (AuthorizationLevel .Anonymous , " get" , " post" , Route = null )] HttpRequest req ,
109
+ [ServiceBus (" TopicOrQueueName" , Connection = " ServiceBusConnection" )] IAsyncCollector < string > message , ILogger log )
110
+ {
111
+ log .LogInformation (" C# HTTP trigger function processed a request." );
112
+
113
+ await message .AddAsync (" MyMessage" );
114
+ await message .AddAsync (" MyMessage2" );
115
+
116
+ string responseMessage = " This HTTP triggered sent a message to Service Bus." ;
117
+
118
+ return new OkObjectResult (responseMessage );
119
+ }
120
+ ```
121
+
66
122
---
67
123
68
124
::: zone-end
0 commit comments