Package version:

A QueueServiceClient represents a URL to the Azure Storage Queue service allowing you to manipulate queues.

Hierarchy

  • StorageClient
    • QueueServiceClient

Constructors

  • Creates an instance of QueueServiceClient.

    Parameters

    • url: string

      A URL string pointing to Azure Storage queue service, such as "https://myaccount.queue.core.windows.net". You can append a SAS if using AnonymousCredential, such as "https://myaccount.queue.core.windows.net?sasString".

    • Optionalcredential: any

      Such as AnonymousCredential, StorageSharedKeyCredential or any credential from the @azure/identity package to authenticate requests to the service. You can also provide an object that implements the TokenCredential interface. If not specified, AnonymousCredential is used.

    • Optionaloptions: StoragePipelineOptions

      Options to configure the HTTP pipeline.

      Example using DefaultAzureCredential from @azure/identity:

      import { DefaultAzureCredential } from "@azure/identity";
      import { QueueServiceClient } from "@azure/storage-queue";

      const account = "<account>";
      const credential = new DefaultAzureCredential();

      const queueServiceClient = new QueueServiceClient(
      `https://${account}.queue.core.windows.net`,
      credential,
      );

      Example using an account name/key:

      import { StorageSharedKeyCredential, QueueServiceClient } from "@azure/storage-queue";

      // Enter your storage account name and shared key
      const account = "<account>";
      const accountKey = "<accountkey>";

      // Use StorageSharedKeyCredential with storage account and account key
      // StorageSharedKeyCredential is only available in Node.js runtime, not in browsers
      const sharedKeyCredential = new StorageSharedKeyCredential(account, accountKey);

      const queueServiceClient = new QueueServiceClient(
      `https://${account}.queue.core.windows.net`,
      sharedKeyCredential,
      {
      retryOptions: { maxTries: 4 }, // Retry options
      userAgentOptions: {
      userAgentPrefix: "BasicSample V10.0.0",
      }, // Customized telemetry string
      },
      );

    Returns QueueServiceClient

  • Creates an instance of QueueServiceClient.

    Parameters

    Returns QueueServiceClient

Properties

accountName: string
storageClientContext: StorageClient

StorageClientContext is a reference to protocol layer operations entry, which is generated by AutoRest generator.

url: string

URL string value.

Methods

  • Only available for QueueServiceClient constructed with a shared key credential.

    Generates an account Shared Access Signature (SAS) URI based on the client properties and parameters passed in. The SAS is signed by the shared key credential of the client.

    Parameters

    • OptionalexpiresOn: any

      Optional. The time at which the shared access signature becomes invalid. Default to an hour later if not specified.

    • permissions: AccountSASPermissions = ...

      Specifies the list of permissions to be associated with the SAS.

    • resourceTypes: string = "sco"

      Specifies the resource types associated with the shared access signature.

    • options: ServiceGenerateAccountSasUrlOptions = {}

      Optional parameters.

    Returns string

    An account SAS URI consisting of the URI to the resource represented by this client, followed by the generated SAS token.

  • Only available for QueueServiceClient constructed with a shared key credential.

    Generates string to sign for an account Shared Access Signature (SAS) URI based on the client properties and parameters passed in. The SAS is signed by the shared key credential of the client.

    Parameters

    • OptionalexpiresOn: any

      Optional. The time at which the shared access signature becomes invalid. Default to an hour later if not specified.

    • permissions: AccountSASPermissions = ...

      Specifies the list of permissions to be associated with the SAS.

    • resourceTypes: string = "sco"

      Specifies the resource types associated with the shared access signature.

    • options: ServiceGenerateAccountSasUrlOptions = {}

      Optional parameters.

    Returns string

    An account SAS URI consisting of the URI to the resource represented by this client, followed by the generated SAS token.

  • Creates a QueueClient object.

    Parameters

    • queueName: string

    Returns QueueClient

    a new QueueClient

    Example usage:

    import { QueueServiceClient } from "@azure/storage-queue";
    import { DefaultAzureCredential } from "@azure/identity";

    const account = "<account>";
    const queueServiceClient = new QueueServiceClient(
    `https://${account}.queue.core.windows.net`,
    new DefaultAzureCredential(),
    );

    const queueName = "<valid queue name>";
    const queueClient = queueServiceClient.getQueueClient(queueName);
    const createQueueResponse = await queueClient.create();
    console.log(
    `Created queue ${queueName} successfully, service assigned request Id: ${createQueueResponse.requestId}`,
    );
  • Returns an async iterable iterator to list all the queues under the specified account.

    .byPage() returns an async iterable iterator to list the queues in pages.

    Example using for await syntax:

    import { QueueServiceClient } from "@azure/storage-queue";
    import { DefaultAzureCredential } from "@azure/identity";

    const account = "<account>";
    const queueServiceClient = new QueueServiceClient(
    `https://${account}.queue.core.windows.net`,
    new DefaultAzureCredential(),
    );

    let i = 1;
    for await (const item of queueServiceClient.listQueues()) {
    console.log(`Queue${i++}: ${item.name}`);
    }

    Example using iter.next():

    import { QueueServiceClient } from "@azure/storage-queue";
    import { DefaultAzureCredential } from "@azure/identity";

    const account = "<account>";
    const queueServiceClient = new QueueServiceClient(
    `https://${account}.queue.core.windows.net`,
    new DefaultAzureCredential(),
    );

    let i = 1;
    const iterator = queueServiceClient.listQueues();
    let { done, value } = await iterator.next();
    while (!done) {
    console.log(`Queue${i++}: ${value.name}`);
    ({ done, value } = await iterator.next());
    }

    Example using byPage():

    import { QueueServiceClient } from "@azure/storage-queue";
    import { DefaultAzureCredential } from "@azure/identity";

    const account = "<account>";
    const queueServiceClient = new QueueServiceClient(
    `https://${account}.queue.core.windows.net`,
    new DefaultAzureCredential(),
    );

    let i = 1;
    for await (const page of queueServiceClient.listQueues().byPage({ maxPageSize: 20 })) {
    for (const item of page.queueItems || []) {
    console.log(`Queue${i++}: ${item.name}`);
    }
    }

    Example using paging with a marker:

    import { QueueServiceClient } from "@azure/storage-queue";
    import { DefaultAzureCredential } from "@azure/identity";

    const account = "<account>";
    const queueServiceClient = new QueueServiceClient(
    `https://${account}.queue.core.windows.net`,
    new DefaultAzureCredential(),
    );

    let i = 1;
    let iterator = queueServiceClient.listQueues().byPage({ maxPageSize: 2 });
    let response = (await iterator.next()).value;
    // Prints 2 queues
    if (response.queueItems) {
    for (const item of response.queueItems) {
    console.log(`Queue${i++}: ${item.name}`);
    }
    }
    // Gets next marker
    let marker = response.continuationToken;
    // Passing next marker as continuationToken
    iterator = queueServiceClient.listQueues().byPage({ continuationToken: marker, maxPageSize: 10 });
    response = (await iterator.next()).value;
    // Prints 10 queues
    if (response.queueItems) {
    for (const item of response.queueItems) {
    console.log(`Queue${i++}: ${item.name}`);
    }
    }

    Parameters

    Returns PagedAsyncIterableIterator<QueueItem, ServiceListQueuesSegmentResponse>

    An asyncIterableIterator that supports paging.

  • Creates an instance of QueueServiceClient.

    Parameters

    • connectionString: string

      Account connection string or a SAS connection string of an Azure storage account. [ Note - Account connection string can only be used in NODE.JS runtime. ] Account connection string example - DefaultEndpointsProtocol=https;AccountName=myaccount;AccountKey=accountKey;EndpointSuffix=core.windows.net SAS connection string example - BlobEndpoint=https://myaccount.blob.core.windows.net/;QueueEndpoint=https://myaccount.queue.core.windows.net/;FileEndpoint=https://myaccount.file.core.windows.net/;TableEndpoint=https://myaccount.table.core.windows.net/;SharedAccessSignature=sasString

    • Optionaloptions: StoragePipelineOptions

      Options to configure the HTTP pipeline.

    Returns QueueServiceClient

    A new QueueServiceClient object from the given connection string.