Esposter
    Preparing search index...

    Class MockQueueClient

    An in-memory mock of the Azure QueueClient. It uses a Map to simulate queue storage and correctly implements the QueueClient interface.

    const mockQueueClient = new MockQueueClient("", "hello world");
    await mockQueueClient.createIfNotExists();
    await mockQueueClient.sendMessage("hello world");
    const messages = await mockQueueClient.peekMessages();

    Implements

    • Except<QueueClient, "accountName">
    Index

    Constructors

    • Parameters

      • connectionString: string
      • queueName: string

      Returns MockQueueClient

    Properties

    connectionString: string
    name: string

    The name of the queue.

    url: string

    URL string value.

    Accessors

    • get queue(): string[]

      Returns string[]

    Methods

    • Clear deletes all messages from a queue.

      Returns Promise<MessagesClearResponse>

      Response data for the clear messages operation.

    • Creates a new queue under the specified account.

      Parameters

      • Optional_options: QueueCreateOptions

      Returns Promise<QueueCreateResponse>

      Response data for the Queue create operation.

      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}`,
      );
    • Creates a new queue under the specified account if it doesn't already exist. If the queue already exists, it is not changed.

      Returns Promise<QueueCreateIfNotExistsResponse>

    • Deletes the specified queue permanently.

      Returns Promise<QueueDeleteResponse>

      Response data for the Queue delete operation.

      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 deleteQueueResponse = await queueClient.delete();
      console.log(
      `Deleted queue successfully, service assigned request Id: ${deleteQueueResponse.requestId}`,
      );
    • Deletes the specified queue permanently if it exists.

      Returns Promise<QueueDeleteIfExistsResponse>

    • deleteMessage permanently removes the specified message from its queue.

      Returns Promise<MessageIdDeleteResponse>

      Response data for the delete message operation.

    • Returns true if the specified queue exists; false otherwise.

      NOTE: use this function with care since an existing queue might be deleted by other clients or applications. Vice versa new queues might be added by other clients or applications after this function completes.

      Returns Promise<boolean>

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

      Generates string to sign for a Service 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.

      Returns string

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

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

      Generates a Service 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.

      Returns string

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

    • Gets details about any stored access policies specified on the queue that may be used with Shared Access Signatures.

      WARNING: JavaScript Date will potential lost precision when parsing start and expiry string. For example, new Date("2018-12-31T03:44:23.8827891Z").toISOString() will get "2018-12-31T03:44:23.882Z".

      Returns Promise<QueueGetAccessPolicyResponse>

      Response data for the Queue get access policy operation.

    • Gets all user-defined metadata and system properties for the specified queue. Metadata is associated with the queue as name-values pairs.

      Returns Promise<QueueGetPropertiesResponse>

      Response data for the Queue get properties operation.

      https://learn.microsoft.com/rest/api/storageservices/get-queue-metadata

      WARNING: The metadata object returned in the response will have its keys in lowercase, even if they originally contained uppercase characters. This differs from the metadata keys returned by the listQueues method of QueueServiceClient using the includeMetadata option, which will retain their original casing.

    • Returns Promise<QueueServiceProperties>

    • Returns AsyncIterableIterator<QueueItem>

    • peekMessages retrieves one or more messages from the front of the queue but does not alter the visibility of the message.

      Parameters

      • Optional_options: QueuePeekMessagesOptions

      Returns Promise<QueuePeekMessagesResponse>

      Response data for the peek messages operation.

      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 peekMessagesResponse = await queueClient.peekMessages();
      console.log(`The peeked message is: ${peekMessagesResponse.peekedMessageItems[0].messageText}`);
    • receiveMessages retrieves one or more messages from the front of the queue.

      Parameters

      • Optional_options: QueueReceiveMessageOptions

      Returns Promise<QueueReceiveMessageResponse>

      Response data for the receive messages operation.

      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 response = await queueClient.receiveMessages();
      if (response.receivedMessageItems.length === 1) {
      const receivedMessageItem = response.receivedMessageItems[0];
      console.log(`Processing & deleting message with content: ${receivedMessageItem.messageText}`);
      const deleteMessageResponse = await queueClient.deleteMessage(
      receivedMessageItem.messageId,
      receivedMessageItem.popReceipt,
      );
      console.log(
      `Delete message successfully, service assigned request Id: ${deleteMessageResponse.requestId}`,
      );
      }
    • sendMessage adds a new message to the back of a queue. The visibility timeout specifies how long the message should be invisible to Dequeue and Peek operations. The message content is up to 64KB in size, and must be in a format that can be included in an XML request with UTF-8 encoding. To include markup in the message, the contents of the message must either be XML-escaped or Base64-encode.

      Parameters

      • messageText: string

        Text of the message to send

      • Optional_options: QueueSendMessageOptions

      Returns Promise<QueueSendMessageResponse>

      Response data for the send messages operation.

      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);
      // Send a message into the queue using the sendMessage method.
      const sendMessageResponse = await queueClient.sendMessage("Hello World!");
      console.log(
      `Sent message successfully, service assigned message Id: ${sendMessageResponse.messageId}, service assigned request Id: ${sendMessageResponse.requestId}`,
      );
    • Sets stored access policies for the queue that may be used with Shared Access Signatures.

      Parameters

      • Optional_identifiers: SignedIdentifier[]

      Returns Promise<QueueSetAccessPolicyResponse>

      Response data for the Queue set access policy operation.

    • Sets one or more user-defined name-value pairs for the specified queue.

      If no option provided, or no metadata defined in the option parameter, the queue metadata will be removed.

      Returns Promise<QueueSetMetadataResponse>

      Response data for the Queue set metadata operation.

    • Update changes a message's visibility timeout and contents. The message content is up to 64KB in size, and must be in a format that can be included in an XML request with UTF-8 encoding. To include markup in the message, the contents of the message must either be XML-escaped or Base64-encode.

      Returns Promise<MessageIdUpdateResponse>

      Response data for the update message operation.