title | description | author | ms.author | ms.date | ms.topic | zone_pivot_groups |
---|---|---|---|---|---|---|
Connect your Java function to Azure Storage |
Learn how to connect an HTTP-triggered Java function to Azure Storage by using a Queue storage output binding. |
KarlErickson |
karler |
10/14/2019 |
quickstart |
java-build-tools-set |
[!INCLUDE functions-add-storage-binding-intro]
This article shows you how to integrate the function you created in the previous quickstart article with an Azure Storage queue. The output binding that you add to this function writes data from an HTTP request to a message in the queue.
Most bindings require a stored connection string that Functions uses to access the bound service. To make this connection easier, you use the Storage account that you created with your function app. The connection to this account is already stored in an app setting named AzureWebJobsStorage
.
Before you start this article, complete the steps in part 1 of the Java quickstart.
[!INCLUDE functions-app-settings-download-cli]
[!INCLUDE functions-extension-bundles]
You can now add the Storage output binding to your project.
[!INCLUDE functions-add-output-binding-java-cli]
[!INCLUDE functions-add-output-binding-java-code]
[!INCLUDE functions-add-output-binding-java-test-cli]
You're now ready to try out the new output binding locally.
As before, use the following command to build the project and start the Functions runtime locally:
mvn clean package
mvn azure-functions:run
gradle jar --info
gradle azureFunctionsRun
Note
Because you enabled extension bundles in the host.json, the Storage binding extension was downloaded and installed for you during startup, along with the other Microsoft binding extensions.
As before, trigger the function from the command line using cURL in a new terminal window:
curl -w "\n" http://localhost:7071/api/HttpTrigger-Java --data AzureFunctions
This time, the output binding also creates a queue named outqueue
in your Storage account and adds a message with this same string.
Next, you use the Azure CLI to view the new queue and verify that a message was added. You can also view your queue by using the Microsoft Azure Storage Explorer or in the Azure portal.
[!INCLUDE functions-storage-account-set-cli]
[!INCLUDE functions-query-storage-cli]
To update your published app, run the following command again:
mvn azure-functions:deploy
gradle azureFunctionsDeploy
Again, you can use cURL to test the deployed function. As before, pass the value AzureFunctions
in the body of the POST request to the URL, as in this example:
curl -w "\n" https://fabrikam-functions-20190929094703749.azurewebsites.net/api/HttpTrigger-Java?code=zYRohsTwBlZ68YF.... --data AzureFunctions
You can examine the Storage queue message again to verify that the output binding generates a new message in the queue, as expected.
[!INCLUDE functions-cleanup-resources]
You've updated your HTTP-triggered function to write data to a Storage queue. To learn more about developing Azure Functions with Java, see the Azure Functions Java developer guide and Azure Functions triggers and bindings. For examples of complete Function projects in Java, see the Java Functions samples.
Next, you should enable Application Insights monitoring for your function app:
[!div class="nextstepaction"] Enable Application Insights integration