Skip to main content
This article explains how to use the Azure Storage Queues client library for .NET to create queues and post messages. It walks through the required libraries, a minimal local example (connection string), how to create a storage account and queue in the Azure portal, and a production-ready Azure Function example that uses Managed Identity (DefaultAzureCredential) to authenticate and post messages to a queue. Keywords: Azure Queue Storage, .NET, Azure.Storage.Queues, Azure Functions, Managed Identity, DefaultAzureCredential, Storage Queue roles

Relevant libraries

Use the Azure SDK packages below to interact with Azure Queue Storage from .NET. The table summarizes each library and when to use it. Recommended links:

Quick example: create a QueueClient using a connection string

This minimal synchronous snippet demonstrates the basic sequence: instantiate a QueueClient using a connection string, create the queue if it doesn’t exist, and send a message. For production use prefer async APIs (CreateIfNotExistsAsync, ExistsAsync, SendMessageAsync) and modern configuration patterns.
Tip: ConfigurationManager.AppSettings is common in .NET Framework. In modern .NET (Core, .NET 5/6/7+) prefer IConfiguration (appsettings.json) or environment variables (Environment.GetEnvironmentVariable) and use the async SDK methods (CreateIfNotExistsAsync, ExistsAsync, SendMessageAsync) for improved scalability.
Now we’ll cover creating a storage account and queue in the Azure portal and show a full Azure Function example that uses a managed identity to write messages to a queue. So we are in the Azure portal. You need a storage account to work with Azure Queue Storage.
A screenshot of the Microsoft Azure portal home page showing service icons across the top (Create a resource, Storage accounts, Function App, etc.) and a table of recent resources with names, types, and last viewed times. The left/right panels show navigation and tools links.
Create a new storage account (the sample uses az204fnqueuewriter in Canada Central with Standard LRS). After the account is created you can add queues from the storage account’s Queues blade — the code examples below will also create the queue at runtime if it does not exist.
A screenshot of the Microsoft Azure portal on the "Create a storage account" Review + create page showing Basics and Advanced settings (subscription, resource group, location, etc.). A notification in the top-right reads "Initializing deployment..." and the cursor is hovering over the Create button.
Open the Queues blade and add a queue (for example, az204) if you prefer creating it manually.
A screenshot of the Microsoft Azure portal with an "Add queue" dialog open, showing a queue name being entered and OK/Cancel buttons. The left sidebar displays storage account navigation items like Containers, Queues, Tables and security/networking options.

Azure Function: post messages to a queue using Managed Identity

This consolidated Azure Function implements a POST endpoint that:
  • Reads the POST body as JSON
  • Uses DefaultAzureCredential to authenticate (function app managed identity)
  • Ensures the queue exists
  • Sends the request body as a queue message
  • Returns appropriate HTTP responses and logs progress
Before deploying, grant the Function App’s managed identity one of the Storage Queue role assignments (for example, Storage Queue Data Contributor or Storage Queue Data Message Sender) on the storage account.
Azure Storage Queue messages have a maximum size of 64 KB. For larger payloads, store content in Blob Storage and send a reference (SAS URL or blob URL) in the queue message instead of the full payload.
Here is the function implementation (async, production-oriented):
Recommended permissions: Grant your Function App’s managed identity access to the storage account via the Access Control (IAM) blade. The following images show the IAM UI for a storage account and the role assignment flow.
A screenshot of the Microsoft Azure portal showing the Access Control (IAM) page for a storage account named "az204fnqueuewriter." The page displays options to view/check access, add role assignments, and panels for viewing role and deny assignments.
Select a role appropriate for your scenario (for example, Storage Queue Data Contributor or Storage Queue Data Message Sender).
Screenshot of the Microsoft Azure "Add role assignment" page. It shows job function roles filtered for "Queue" and lists four built-in Storage Queue roles (Data Contributor, Data Message Processor, Data Message Sender, Data Reader) with descriptions and View links.
Assign the role to the Function App’s managed identity.
Screenshot of the Microsoft Azure portal's "Add role assignment" (Access Control/IAM) page. It shows assigning the "Storage Queue Data Contributor" role to a managed identity, with a right-hand pane for selecting a Function App managed identity.
After assigning the role, deploy the Function App and test it. You can call the function from Postman or from the portal’s Test/Run tab. Ensure you provide the function key in the query string or headers and set Content-Type: application/json. Example auto-generated function.json (for reference):
Example POST payload:
Sample function logs when a message is successfully added:

Viewing and verifying messages

To verify messages inserted by the function:
  • Open Microsoft Storage Explorer or the portal’s Queues blade for your storage account.
  • Refresh the queue view and open the queue (for example, az204) to inspect messages.
  • Messages can then be processed by another function, written to a database (e.g., Cosmos DB), or consumed by any downstream service.
Useful link:

Summary

You have seen how to:
  • Configure and use the Azure Storage Queues client (Azure.Storage.Queues) in .NET
  • Create queues at runtime or manually in the portal
  • Use DefaultAzureCredential / managed identity in an Azure Function to post messages securely
  • Assign appropriate Storage Queue role permissions to the function app identity
  • Verify messages using Storage Explorer or the portal
This completes coverage for creating and managing Azure Queue Storage queues and messages using .NET. For related messaging patterns (e.g., advanced pub/sub or topic semantics), consider Azure Service Bus depending on your requirements.

Watch Video

Practice Lab