You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
title: Add messages to an Azure Storage queue using Functions
3
-
description: Use Azure Functions to create a serverless function that is invoked by an HTTP request and creates a message in an Azure Storage queue.
4
-
5
-
ms.assetid: 0b609bc0-c264-4092-8e3e-0784dcc23b5d
3
+
description: Use Azure Functions to create a serverless function that's triggered by an HTTP request and creates a message in an Azure Storage queue.
4
+
ms.service: azure-functions
6
5
ms.topic: how-to
7
-
ms.date: 04/24/2020
6
+
ms.date: 06/19/2024
8
7
ms.devlang: csharp
9
8
# ms.devlang: csharp, javascript
10
9
ms.custom: "devx-track-csharp, mvc"
11
10
11
+
#Customer intent: As a function developer, I want to learn how to use Azure Functions to create a serverless function that's triggered by an HTTP request so that I can create a message in an Azure Storage queue.
12
+
12
13
---
13
14
# Add messages to an Azure Storage queue using Functions
14
15
15
-
In Azure Functions, input and output bindings provide a declarative way to make data from external services available to your code. In this quickstart, you use an output binding to create a message in a queue when a function is triggered by an HTTP request. You use Azure storage container to view the queue messages that your function creates.
16
+
In Azure Functions, input and output bindings provide a declarative way to make data from external services available to your code. In this article, you use an output binding to create a message in a queue when an HTTP request triggers a function. You use Azure storage container to view the queue messages that your function creates.
16
17
17
18
## Prerequisites
18
19
19
-
To complete this quickstart:
20
-
21
20
- An Azure subscription. If you don't have one, create a [free account](https://azure.microsoft.com/free/?WT.mc_id=A261C142F) before you begin.
22
21
23
-
- Follow the directions in [Create your first function from the Azure portal](./functions-get-started.md) and don't do the **Clean up resources** step. That quickstart creates the function app and function that you use here.
22
+
- Follow the directions in [Create your first function in the Azure portal](./functions-create-function-app-portal.md), omitting the **Clean up resources** step, to create the function app and function to use in this article.
24
23
25
-
## <aname="add-binding"></a>Add an output binding
24
+
## Add an output binding
26
25
27
-
In this section, you use the portal UI to add a queue storage output binding to the function you created earlier. This binding makes it possible to write minimal code to create a message in a queue. You don't have to write code for tasks such as opening a storage connection, creating a queue, or getting a reference to a queue. The Azure Functions runtime and queue output binding take care of those tasks for you.
26
+
In this section, you use the portal UI to add an Azure Queue Storage output binding to the function you created in the prerequisites. This binding makes it possible to write minimal code to create a message in a queue. You don't need to write code for such tasks as opening a storage connection, creating a queue, or getting a reference to a queue. The Azure Functions runtime and queue output binding take care of those tasks for you.
28
27
29
-
1. In the Azure portal, open the function app page for the function app that you created in [Create your first function from the Azure portal](./functions-get-started.md). To do open the page, search for and select **Function App**. Then, select your function app.
28
+
1. In the Azure portal, search for and select the function app that you created in [Create your first function from the Azure portal](./functions-get-started.md).
30
29
31
-
1.Select your function app, and then select the function that you created in that earlier quickstart.
30
+
1.In your function app, select the function that you created.
32
31
33
32
1. Select **Integration**, and then select **+ Add output**.
34
33
35
-
:::image type="content" source="./media/functions-integrate-storage-queue-output-binding/function-create-output-binding.png" alt-text="Create an output binding for your function." border="true":::
34
+
:::image type="content" source="./media/functions-integrate-storage-queue-output-binding/function-create-output-binding.png" alt-text="Screenshot that shows how to create an output binding for your function." lightbox="./media/functions-integrate-storage-queue-output-binding/function-create-output-binding.png":::
35
+
36
+
1. Select the **Azure Queue Storage** binding type and add the settings as specified in the table that follows this screenshot:
36
37
37
-
1. Select the **Azure Queue Storage**binding type, and add the settings as specified in the table that follows this screenshot:
38
+
:::image type="content" source="./media/functions-integrate-storage-queue-output-binding/function-create-output-binding-details.png" alt-text="Screenshot that shows how to add a Queue Storage output binding to a function in the Azure portal.":::
38
39
39
-
:::image type="content" source="./media/functions-integrate-storage-queue-output-binding/function-create-output-binding-details.png" alt-text="Add a Queue storage output binding to a function in the Azure portal." border="true":::
|**Message parameter name**| outputQueueItem | The name of the output binding parameter. |
44
-
|**Queue name**| outqueue | The name of the queue to connect to in your Storage account. |
45
-
|**Storage account connection**| AzureWebJobsStorage | You can use the storage account connection already being used by your function app, or create a new one. |
42
+
|**Message parameter name**| outputQueueItem | The name of the output binding parameter. |
43
+
|**Queue name**| outqueue | The name of the queue to connect to in your storage account. |
44
+
|**Storage account connection**| AzureWebJobsStorage | You can use the existing storage account connection used by your function app or create a new one. |
46
45
47
46
1. Select **OK** to add the binding.
48
47
49
48
Now that you have an output binding defined, you need to update the code to use the binding to add messages to a queue.
50
49
51
50
## Add code that uses the output binding
52
51
53
-
In this section, you add code that writes a message to the output queue. The message includes the value that is passed to the HTTP trigger in the query string. For example, if the query string includes `name=Azure`, the queue message will be*Name passed to the function: Azure*.
52
+
In this section, you add code that writes a message to the output queue. The message includes the value passed to the HTTP trigger in the query string. For example, if the query string includes `name=Azure`, the queue message is*Name passed to the function: Azure*.
54
53
55
54
1. In your function, select **Code + Test** to display the function code in the editor.
56
55
57
-
1. Update the function code depending on your function language:
56
+
1. Update the function code, according to your function language:
58
57
59
58
# [C\#](#tab/csharp)
60
59
61
-
Add an **outputQueueItem** parameter to the method signature as shown in the following example.
60
+
Add an **outputQueueItem** parameter to the method signature as shown in the following example:
:::imagetype="content"source="./media/functions-integrate-storage-queue-output-binding/functions-test-run-function.png"alt-text="Test the queue storage binding in the Azure portal."border="true":::
:::imagetype="content"source="./media/functions-integrate-storage-queue-output-binding/functions-test-run-function.png"alt-text="Screenshot that shows how to test the Queue Storage binding in the Azure portal."lightbox="./media/functions-integrate-storage-queue-output-binding/functions-test-run-function.png":::
Anewqueuenamed**outqueue**iscreatedinyourStorageaccountbytheFunctionsruntime when the output binding is first used. You'll use storage account to verify that the queue and a message in it were created.
Anewqueuenamed**outqueue**iscreatedinyourstorageaccountbytheFunctionsruntime when the output binding is first used. You use storage account to verify that the queue and a message in it were created.
106
104
105
+
### Find the storage account connected to AzureWebJobsStorage
:::imagetype="content"source="./media/functions-integrate-storage-queue-output-binding/function-find-storage-account.png"alt-text="Screenshot shows the Configuration page with AzureWebJobsStorage selected."border="true":::
111
+
:::imagetype="content"source="./media/functions-integrate-storage-queue-output-binding/function-find-storage-account.png"alt-text="Screenshot that shows the Configuration page with AzureWebJobsStorage selected."lightbox="./media/functions-integrate-storage-queue-output-binding/function-find-storage-account.png":::
113
112
114
113
1. Locateandmakenoteoftheaccountname.
115
114
116
-
:::imagetype="content"source="./media/functions-integrate-storage-queue-output-binding/function-storage-account-name.png"alt-text="Locate the storage account connected to AzureWebJobsStorage."border="true":::
115
+
:::imagetype="content"source="./media/functions-integrate-storage-queue-output-binding/function-storage-account-name.png"alt-text="Screenshot that shows how to locate the storage account connected to AzureWebJobsStorage."lightbox="./media/functions-integrate-storage-queue-output-binding/function-storage-account-name.png":::
117
116
118
117
### Examine the output queue
119
118
120
-
1. Intheresourcegroupforyourfunctionapp, selectthestorageaccountthatyou're using for this quickstart.
Inthisquickstart, youaddedanoutputbindingtoanexistingfunction. FormoreinformationaboutbindingtoQueuestorage, see [AzureFunctionsStoragequeuebindings](functions-bindings-storage-queue.md).
133
+
Inthisarticle, youaddedanoutputbindingtoanexistingfunction. FormoreinformationaboutbindingtoQueueStorage, see [QueueStoragetriggerandbindings](functions-bindings-storage-queue.md).
0 commit comments