Bagikan melalui


QueueServiceClient class

QueueServiceClient mewakili URL ke layanan Antrean Azure Storage yang memungkinkan Anda memanipulasi antrean.

Memperluas

StorageClient

Konstruktor

QueueServiceClient(string, Pipeline)

Membuat instans QueueServiceClient.

QueueServiceClient(string, StorageSharedKeyCredential | AnonymousCredential | TokenCredential, StoragePipelineOptions)

Membuat instans QueueServiceClient.

Properti yang Diwariskan

accountName
url

Nilai string URL.

Metode

createQueue(string, QueueCreateOptions)

Membuat antrean baru di bawah akun yang ditentukan.

Lihat https://learn.microsoft.com/rest/api/storageservices/create-queue4

deleteQueue(string, QueueDeleteOptions)

Menghapus antrean yang ditentukan secara permanen.

Lihat https://learn.microsoft.com/rest/api/storageservices/delete-queue3

fromConnectionString(string, StoragePipelineOptions)

Membuat instans QueueServiceClient.

generateAccountSasUrl(Date, AccountSASPermissions, string, ServiceGenerateAccountSasUrlOptions)

Hanya tersedia untuk QueueServiceClient yang dibangun dengan kredensial kunci bersama.

Menghasilkan URI Tanda Tangan Akses Bersama (SAS) akun berdasarkan properti dan parameter klien yang diteruskan. SAS ditandatangani oleh kredensial kunci bersama klien.

Lihat https://learn.microsoft.com/rest/api/storageservices/create-account-sas

generateSasStringToSign(Date, AccountSASPermissions, string, ServiceGenerateAccountSasUrlOptions)

Hanya tersedia untuk QueueServiceClient yang dibangun dengan kredensial kunci bersama.

Menghasilkan string untuk masuk ke akun URI Tanda Tangan Akses Bersama (SAS) berdasarkan properti klien dan parameter yang diteruskan. SAS ditandatangani oleh kredensial kunci bersama klien.

Lihat https://learn.microsoft.com/rest/api/storageservices/create-account-sas

getProperties(ServiceGetPropertiesOptions)

Mendapatkan properti layanan Antrean akun penyimpanan, termasuk properti untuk aturan Storage Analytics dan CORS (Berbagi Sumber Daya Lintas Asal).

Lihat https://learn.microsoft.com/rest/api/storageservices/get-queue-service-properties

getQueueClient(string)

Membuat objek QueueClient.

getStatistics(ServiceGetStatisticsOptions)

Mengambil statistik yang terkait dengan replikasi untuk layanan Antrean. Ini hanya tersedia di titik akhir lokasi sekunder ketika replikasi geo-redundan akses baca diaktifkan untuk akun penyimpanan.

Lihat https://learn.microsoft.com/rest/api/storageservices/get-queue-service-stats

getUserDelegationKey(Date, Date, ServiceGetUserDelegationKeyOptions)

HANYA TERSEDIA SAAT MENGGUNAKAN AUTENTIKASI TOKEN PEMBAWA (TokenCredential).

Mengambil kunci delegasi pengguna untuk layanan Antrean. Ini hanya operasi yang valid saat menggunakan autentikasi token pembawa.

Lihat https://learn.microsoft.com/rest/api/storageservices/get-user-delegation-key

listQueues(ServiceListQueuesOptions)

Mengembalikan iterator yang dapat diulang asinkron untuk mencantumkan semua antrean di bawah akun yang ditentukan.

.byPage() mengembalikan iterator yang dapat diulang asinkron untuk mencantumkan antrean di halaman.

Contoh menggunakan sintaks for await:

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}`);
}

Contoh menggunakan 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());
}

Contoh menggunakan 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}`);
  }
}

Contoh menggunakan halaman dengan penanda:

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}`);
  }
}
setProperties(QueueServiceProperties, ServiceGetPropertiesOptions)

Mengatur properti untuk titik akhir layanan Antrean akun penyimpanan, termasuk properti untuk aturan Storage Analytics, CORS (Berbagi Sumber Daya Lintas Asal), dan pengaturan penghapusan sementara.

Lihat https://learn.microsoft.com/rest/api/storageservices/set-queue-service-properties

Detail Konstruktor

QueueServiceClient(string, Pipeline)

Membuat instans QueueServiceClient.

new QueueServiceClient(url: string, pipeline: Pipeline)

Parameter

url

string

String URL yang menunjuk ke layanan antrean Azure Storage, seperti "https://myaccount.queue.core.windows.net". Anda dapat menambahkan SAS jika menggunakan AnonymousCredential, seperti "https://myaccount.queue.core.windows.net?sasString".

pipeline
Pipeline

Panggil newPipeline() untuk membuat alur default, atau sediakan alur yang disesuaikan.

QueueServiceClient(string, StorageSharedKeyCredential | AnonymousCredential | TokenCredential, StoragePipelineOptions)

Membuat instans QueueServiceClient.

new QueueServiceClient(url: string, credential?: StorageSharedKeyCredential | AnonymousCredential | TokenCredential, options?: StoragePipelineOptions)

Parameter

url

string

String URL yang menunjuk ke layanan antrean Azure Storage, seperti "https://myaccount.queue.core.windows.net". Anda dapat menambahkan SAS jika menggunakan AnonymousCredential, seperti "https://myaccount.queue.core.windows.net?sasString".

credential

StorageSharedKeyCredential | AnonymousCredential | TokenCredential

Seperti AnonymousCredential, StorageSharedKeyCredential atau kredensial apa pun dari paket @azure/identity untuk mengautentikasi permintaan ke layanan. Anda juga dapat menyediakan objek yang mengimplementasikan antarmuka TokenCredential. Jika tidak ditentukan, AnonymousCredential digunakan.

options
StoragePipelineOptions

Opsi untuk mengonfigurasi alur HTTP.

Contoh menggunakan DefaultAzureCredential dari @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,
);

Contoh menggunakan nama/kunci akun:

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
  },
);

Detail Properti yang Diwariskan

accountName

accountName: string

Nilai Properti

string

Diwarisi Dari StorageClient.accountName

url

Nilai string URL.

url: string

Nilai Properti

string

Diwariskan Dari StorageClient.url

Detail Metode

createQueue(string, QueueCreateOptions)

Membuat antrean baru di bawah akun yang ditentukan.

Lihat https://learn.microsoft.com/rest/api/storageservices/create-queue4

function createQueue(queueName: string, options?: QueueCreateOptions): Promise<QueueCreateResponse>

Parameter

queueName

string

nama antrean yang akan dibuat

options
QueueCreateOptions

Opsi untuk mengantre membuat operasi.

Mengembalikan

Data respons untuk operasi pembuatan Antrean.

deleteQueue(string, QueueDeleteOptions)

Menghapus antrean yang ditentukan secara permanen.

Lihat https://learn.microsoft.com/rest/api/storageservices/delete-queue3

function deleteQueue(queueName: string, options?: QueueDeleteOptions): Promise<QueueDeleteResponse>

Parameter

queueName

string

nama antrean yang akan dihapus.

options
QueueDeleteOptions

Opsi untuk operasi penghapusan antrean.

Mengembalikan

Data respons untuk operasi penghapusan Antrean.

fromConnectionString(string, StoragePipelineOptions)

Membuat instans QueueServiceClient.

static function fromConnectionString(connectionString: string, options?: StoragePipelineOptions): QueueServiceClient

Parameter

connectionString

string

String koneksi akun atau string koneksi SAS dari akun penyimpanan Azure. [ Catatan - String koneksi akun hanya dapat digunakan dalam runtime NODE.JS. ] Contoh string koneksi akun - contoh string koneksi SAS DefaultEndpointsProtocol=https;AccountName=myaccount;AccountKey=accountKey;EndpointSuffix=core.windows.net - 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

options
StoragePipelineOptions

Opsi untuk mengonfigurasi alur HTTP.

Mengembalikan

Objek QueueServiceClient baru dari string koneksi yang diberikan.

generateAccountSasUrl(Date, AccountSASPermissions, string, ServiceGenerateAccountSasUrlOptions)

Hanya tersedia untuk QueueServiceClient yang dibangun dengan kredensial kunci bersama.

Menghasilkan URI Tanda Tangan Akses Bersama (SAS) akun berdasarkan properti dan parameter klien yang diteruskan. SAS ditandatangani oleh kredensial kunci bersama klien.

Lihat https://learn.microsoft.com/rest/api/storageservices/create-account-sas

function generateAccountSasUrl(expiresOn?: Date, permissions?: AccountSASPermissions, resourceTypes?: string, options?: ServiceGenerateAccountSasUrlOptions): string

Parameter

expiresOn

Date

Optional. Waktu tanda tangan akses bersama menjadi tidak valid. Default ke satu jam kemudian jika tidak ditentukan.

permissions
AccountSASPermissions

Menentukan daftar izin yang akan dikaitkan dengan SAS.

resourceTypes

string

Menentukan jenis sumber daya yang terkait dengan tanda tangan akses bersama.

options
ServiceGenerateAccountSasUrlOptions

Parameter opsional.

Mengembalikan

string

Akun SAS URI yang terdiri dari URI ke sumber daya yang diwakili oleh klien ini, diikuti oleh token SAS yang dihasilkan.

generateSasStringToSign(Date, AccountSASPermissions, string, ServiceGenerateAccountSasUrlOptions)

Hanya tersedia untuk QueueServiceClient yang dibangun dengan kredensial kunci bersama.

Menghasilkan string untuk masuk ke akun URI Tanda Tangan Akses Bersama (SAS) berdasarkan properti klien dan parameter yang diteruskan. SAS ditandatangani oleh kredensial kunci bersama klien.

Lihat https://learn.microsoft.com/rest/api/storageservices/create-account-sas

function generateSasStringToSign(expiresOn?: Date, permissions?: AccountSASPermissions, resourceTypes?: string, options?: ServiceGenerateAccountSasUrlOptions): string

Parameter

expiresOn

Date

Optional. Waktu tanda tangan akses bersama menjadi tidak valid. Default ke satu jam kemudian jika tidak ditentukan.

permissions
AccountSASPermissions

Menentukan daftar izin yang akan dikaitkan dengan SAS.

resourceTypes

string

Menentukan jenis sumber daya yang terkait dengan tanda tangan akses bersama.

options
ServiceGenerateAccountSasUrlOptions

Parameter opsional.

Mengembalikan

string

Akun SAS URI yang terdiri dari URI ke sumber daya yang diwakili oleh klien ini, diikuti oleh token SAS yang dihasilkan.

getProperties(ServiceGetPropertiesOptions)

Mendapatkan properti layanan Antrean akun penyimpanan, termasuk properti untuk aturan Storage Analytics dan CORS (Berbagi Sumber Daya Lintas Asal).

Lihat https://learn.microsoft.com/rest/api/storageservices/get-queue-service-properties

function getProperties(options?: ServiceGetPropertiesOptions): Promise<ServiceGetPropertiesResponse>

Parameter

options
ServiceGetPropertiesOptions

Opsi untuk mendapatkan operasi properti.

Mengembalikan

Data respons termasuk properti layanan antrean.

getQueueClient(string)

Membuat objek QueueClient.

function getQueueClient(queueName: string): QueueClient

Parameter

queueName

string

Mengembalikan

QueueClient baru

Contoh penggunaan:

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}`,
);

getStatistics(ServiceGetStatisticsOptions)

Mengambil statistik yang terkait dengan replikasi untuk layanan Antrean. Ini hanya tersedia di titik akhir lokasi sekunder ketika replikasi geo-redundan akses baca diaktifkan untuk akun penyimpanan.

Lihat https://learn.microsoft.com/rest/api/storageservices/get-queue-service-stats

function getStatistics(options?: ServiceGetStatisticsOptions): Promise<ServiceGetStatisticsResponse>

Parameter

options
ServiceGetStatisticsOptions

Opsi untuk mendapatkan operasi statistik.

Mengembalikan

Data respons untuk mendapatkan statistik operasi.

getUserDelegationKey(Date, Date, ServiceGetUserDelegationKeyOptions)

HANYA TERSEDIA SAAT MENGGUNAKAN AUTENTIKASI TOKEN PEMBAWA (TokenCredential).

Mengambil kunci delegasi pengguna untuk layanan Antrean. Ini hanya operasi yang valid saat menggunakan autentikasi token pembawa.

Lihat https://learn.microsoft.com/rest/api/storageservices/get-user-delegation-key

function getUserDelegationKey(startsOn: Date, expiresOn: Date, options?: ServiceGetUserDelegationKeyOptions): Promise<ServiceGetUserDelegationKeyResponse>

Parameter

startsOn

Date

Waktu mulai untuk SAS delegasi pengguna. Harus dalam waktu 7 hari dari waktu saat ini

expiresOn

Date

Waktu akhir untuk SAS delegasi pengguna. Harus dalam waktu 7 hari dari waktu saat ini

Mengembalikan

listQueues(ServiceListQueuesOptions)

Mengembalikan iterator yang dapat diulang asinkron untuk mencantumkan semua antrean di bawah akun yang ditentukan.

.byPage() mengembalikan iterator yang dapat diulang asinkron untuk mencantumkan antrean di halaman.

Contoh menggunakan sintaks for await:

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}`);
}

Contoh menggunakan 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());
}

Contoh menggunakan 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}`);
  }
}

Contoh menggunakan halaman dengan penanda:

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}`);
  }
}
function listQueues(options?: ServiceListQueuesOptions): PagedAsyncIterableIterator<QueueItem, ServiceListQueuesSegmentResponse, PageSettings>

Parameter

options
ServiceListQueuesOptions

Opsi untuk mencantumkan operasi antrean.

Mengembalikan

AsyncIterableIterator yang mendukung halaman.

setProperties(QueueServiceProperties, ServiceGetPropertiesOptions)

Mengatur properti untuk titik akhir layanan Antrean akun penyimpanan, termasuk properti untuk aturan Storage Analytics, CORS (Berbagi Sumber Daya Lintas Asal), dan pengaturan penghapusan sementara.

Lihat https://learn.microsoft.com/rest/api/storageservices/set-queue-service-properties

function setProperties(properties: QueueServiceProperties, options?: ServiceGetPropertiesOptions): Promise<ServiceSetPropertiesResponse>

Parameter

options
ServiceGetPropertiesOptions

Opsi untuk mengatur operasi properti.

Mengembalikan

Data respons untuk operasi Atur Properti.