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
@@ -14,84 +14,24 @@ In this article, you integrate an Azure Storage queue with the function and stor
14
14
15
15
Before you begin, you must complete the article, [Quickstart: Create an Azure Functions project from the command line](functions-create-first-azure-function-azure-cli.md). If you already cleaned up resources at the end of that article, go through the steps again to recreate the function app and related resources in Azure.
16
16
17
-
## Retrieve the Azure Storage connection string
18
-
19
-
When you created a function app in Azure in the previous quickstart, you also created a Storage account. The connection string for this account is stored securely in app settings in Azure. By downloading the setting into the *local.settings.json* file, you can use that connection write to a Storage queue in the same account when running the function locally.
20
-
21
-
1. From the root of the project, run the following command, replacing `<APP_NAME>` with the name of your function app from the previous quickstart. This command will overwrite any existing values in the file.
1. Open *local.settings.json* and locate the value named `AzureWebJobsStorage`, which is the Storage account connection string. You use the name `AzureWebJobsStorage` and the connection string in other sections of this article.
28
-
29
-
> [!IMPORTANT]
30
-
> Because *local.settings.json* contains secrets downloaded from Azure, always exclude this file from source control. The *.gitignore* file created with a local functions project excludes the file by default.
## Add an output binding definition to the function
35
-
36
-
Although a function can have only one trigger, it can have multiple input and output bindings, which let you connect to other Azure services and resources without writing custom integration code.
37
-
38
-
::: zone pivot="programming-language-python,programming-language-javascript,programming-language-powershell,programming-language-typescript"
39
-
You declare these bindings in the *function.json* file in your function folder. From the previous quickstart, your *function.json* file in the *HttpExample* folder contains two bindings in the `bindings` collection:
40
-
::: zone-end
41
-
42
-
::: zone pivot="programming-language-javascript,programming-language-typescript"
::: zone pivot="programming-language-python,programming-language-javascript, programming-language-powershell, programming-language-typescript"
55
-
Each binding has at least a type, a direction, and a name. In the example above, the first binding is of type `httpTrigger` with the direction `in`. For the `in` direction, `name` specifies the name of an input parameter that's sent to the function when invoked by the trigger.
56
-
::: zone-end
57
-
58
-
::: zone pivot="programming-language-javascript,programming-language-typescript"
59
-
The second binding in the collection is named `res`. This `http` binding is an output binding (`out`) that is used to write the HTTP response.
60
-
61
-
To write to an Azure Storage queue from this function, add an `out` binding of type `queue` with the name `msg`, as shown in the code below:
The second binding in the collection is of type `http` with the direction `out`, in which case the special `name` of `$return` indicates that this binding uses the function's return value rather than providing an input parameter.
68
-
69
-
To write to an Azure Storage queue from this function, add an `out` binding of type `queue` with the name `msg`, as shown in the code below:
::: zone pivot="programming-language-python,programming-language-javascript,programming-language-powershell,programming-language-typescript"
83
-
In this case, `msg` is given to the function as an output argument. For a `queue` type, you must also specify the name of the queue in `queueName` and provide the *name* of the Azure Storage connection (from *local.settings.json*) in `connection`.
For more information on the details of bindings, see [Azure Functions triggers and bindings concepts](functions-triggers-bindings.md) and [queue output configuration](functions-bindings-storage-queue-output.md#configuration).
91
31
92
32
## Add code to use the output binding
93
33
94
-
With the queue binding specified in *function.json*, you can now update your function to receive the `msg` output parameter and write messages to the queue.
34
+
With the queue binding defined, you can now update your function to receive the `msg` output parameter and write messages to the queue.
Observe that you *don't* need to write any code for authentication, getting a queue reference, or writing data. All these integration tasks are conveniently handled in the Azure Functions runtime and queue output binding.
@@ -121,72 +67,30 @@ Observe that you *don't* need to write any code for authentication, getting a qu
121
67
122
68
## View the message in the Azure Storage queue
123
69
124
-
You can view the queue in the [Azure portal](../storage/queues/storage-quickstart-queues-portal.md) or in the [Microsoft Azure Storage Explorer](https://storageexplorer.com/). You can also view the queue in the Azure CLI, as described in the following steps:
125
-
126
-
1. Open the function project's *local.setting.json* file and copy the connection string value. In a terminal or command window, run the following command to create an environment variable named `AZURE_STORAGE_CONNECTION_STRING`, pasting your specific connection string in place of `<MY_CONNECTION_STRING>`. (This environment variable means you don't need to supply the connection string to each subsequent command using the `--connection-string` argument.)
set AZURE_STORAGE_CONNECTION_STRING="<MY_CONNECTION_STRING>"
144
-
```
145
-
146
-
---
147
-
148
-
1. (Optional) Use the [`az storage queue list`](/cli/azure/storage/queue#az-storage-queue-list) command to view the Storage queues in your account. The output from this command should include a queue named `outqueue`, which was created when the function wrote its first message to that queue.
149
-
150
-
```azurecli
151
-
az storage queue list --output tsv
152
-
```
72
+
## Redeploy the project to Azure
153
73
154
-
1. Use the [`az storage message get`](/cli/azure/storage/message#az-storage-message-get) command to read the message from this queue, which should be the first name you used when testing the function earlier. The command reads and removes the first message from the queue.
74
+
Now that you've verified locally that the function wrote a messageto the Azure Storage queue, you can redeploy your project to update the endpoint running on Azure.
[System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($(az storage message get --queue-name outqueue -o tsv --query '[].{Message:content}')))
166
-
```
167
-
168
-
# [Azure CLI](#tab/cmd)
169
-
170
-
```azurecli
171
-
az storage message get --queue-name outqueue -o tsv --query [].{Message:content} > %TEMP%out.b64 && certutil -decode -f %TEMP%out.b64 %TEMP%out.txt > NUL && type %TEMP%out.txt && del %TEMP%out.b64 %TEMP%out.txt /q
172
-
```
76
+
::: zone pivot="programming-language-javascript,programming-language-typescript,programming-language-python,programming-language-powershell,programming-language-csharp"
77
+
In the *LocalFunctionsProj* folder, use the [`func azure functionapp publish`](functions-run-local.md#project-file-deployment) command to redeploy the project, replacing`<APP_NAME>` with the name of your app.
173
78
174
-
This script uses certutil to decode the base64-encoded message collection from a local temp file. If there's no output, try removing `> NUL` from the script to stop suppressing certutil output, in case there's an error.
175
-
176
-
---
177
-
178
-
Because the message body is stored [base64 encoded](functions-bindings-storage-queue-trigger.md#encoding), the message must be decoded before it's displayed. After you execute `az storage message get`, the message is removed from the queue. If there was only one message in `outqueue`, you won't retrieve a message when you run this command a second time and instead get an error.
79
+
```
80
+
func azure functionapp publish <APP_NAME>
81
+
```
82
+
::: zone-end
179
83
180
-
## Redeploy the project to Azure
84
+
::: zone pivot="programming-language-java"
181
85
182
-
Now that you've verified locally that the function wrote a message to the Azure Storage queue, you can redeploy your project to update the endpoint running on Azure.
86
+
In the local project folder, use the following Maven command to republish your project:
87
+
```
88
+
mvn azure-functions:deploy
89
+
```
90
+
::: zone-end
183
91
184
-
1. In the *LocalFunctionsProj* folder, use the [`func azure functionapp publish`](functions-run-local.md#project-file-deployment) command to redeploy the project, replacing`<APP_NAME>` with the name of your app.
92
+
## Verify in Azure
185
93
186
-
```
187
-
func azure functionapp publish <APP_NAME>
188
-
```
189
-
190
94
1. As in the previous quickstart, use a browser or CURL to test the redeployed function.
0 commit comments