How to use the command az storage queue (with examples)

How to use the command az storage queue (with examples)

The az storage queue command is part of the Azure CLI (az) and is used to manage storage queues in Azure. Storage queues are used to send and receive messages between different components of an application.

Use case 1: Create a queue

Code:

az storage queue create --account-name storage_account_name --name queue_name --metadata queue_metadata

Motivation: Creating a storage queue is the first step in setting up a messaging system for an application. This command allows users to create a new queue with a given name and specify any metadata for the queue.

Explanation:

  • --account-name: the name of the storage account where the queue will be created
  • --name: the name of the queue to be created
  • --metadata: any metadata to be associated with the queue

Example output:

{
  "approximate_messages_count": 0,
  "metadata": {
    "foo": "bar"
  },
  "name": "queue_name",
  "properties": {
    "metadata": {},
    "message_count": 0,
    "last_updated": "2022-01-01T00:00:00Z",
    "max_size": 1024
  }
}

Use case 2: Generate a shared access signature for the queue

Code:

az storage queue generate-sas --account-name storage_account_name --name queue_name --permissions queue_permissions --expiry expiry_date --https-only

Motivation: Shared access signatures (SAS) provide a secure way to grant limited access to storage resources. Generating a SAS for a queue allows users to define specific permissions, set an expiration date, and enforce HTTPS-only access.

Explanation:

  • --account-name: the name of the storage account containing the queue
  • --name: the name of the queue for which to generate the SAS
  • --permissions: the permissions to grant for the SAS (e.g., “r” for read, “a” for add)
  • --expiry: the expiration date and time for the SAS in UTC format
  • --https-only: indicates that the SAS can only be used over HTTPS

Example output:

https://storage_account_name.queue.core.windows.net/queue_name?sv=2018-03-28&ss=q&srt=o&sp=r&se=2022-01-01T00%3A00%3A00Z&st=2022-01-01T00%3A00%3A00Z&spr=https&sig=signature

Use case 3: List queues in a storage account

Code:

az storage queue list --prefix filter_prefix --account-name storage_account_name

Motivation: When working with a storage account that contains multiple queues, listing them can provide an overview of the available queues and their properties. The --prefix argument can be used to filter the list based on a specific prefix.

Explanation:

  • --prefix: the prefix to filter queues by
  • --account-name: the name of the storage account to list queues for

Example output:

[
  {
    "approximate_messages_count": 0,
    "metadata": {
      "foo": "bar"
    },
    "name": "queue_name1",
    "properties": {
      "metadata": {},
      "message_count": 0,
      "last_updated": "2022-01-01T00:00:00Z",
      "max_size": 1024
    }
  },
  {
    "approximate_messages_count": 0,
    "metadata": {
      "baz": "qux"
    },
    "name": "queue_name2",
    "properties": {
      "metadata": {},
      "message_count": 0,
      "last_updated": "2022-01-01T00:00:00Z",
      "max_size": 2048
    }
  }
]

Use case 4: Delete a queue

Code:

az storage queue delete --account-name storage_account_name --name queue_name --fail-not-exist

Motivation: Deleting a queue is necessary when it is no longer needed or when it needs to be recreated. This command allows users to delete a specific queue and any messages it contains, with the option to fail if the queue does not exist.

Explanation:

  • --account-name: the name of the storage account containing the queue to be deleted
  • --name: the name of the queue to be deleted
  • --fail-not-exist: indicates that the command should fail if the specified queue does not exist

Example output:

{
  "message": "The specified queue does not exist."
}

Conclusion:

The az storage queue command provides a comprehensive set of features for managing storage queues in Azure. By using this command, users can create queues, generate shared access signatures, list queues, and delete queues, allowing them to build reliable messaging systems for their applications.

Related Posts

How to use the command 'rapper' (with examples)

How to use the command 'rapper' (with examples)

The rapper command is part of the Raptor RDF Syntax Library and is used for parsing RDF (Resource Description Framework) documents.

Read More
How to use the command 'maestral' (with examples)

How to use the command 'maestral' (with examples)

Maestral is a lightweight Dropbox client for macOS and Linux. It provides a command-line interface (CLI) that allows users to interact with their Dropbox account and perform different actions such as starting the GUI, checking the syncing status, pausing or resuming syncing, and getting the sync status of specific files or folders.

Read More
How to use the command 'kustomize' (with examples)

How to use the command 'kustomize' (with examples)

Kustomize is a command-line tool that allows you to customize Kubernetes resources before deploying them.

Read More