[Storage-Queue][Samples] add a scenario of receiving more than one messages with `receiveMessages()` (#21704)
* added new scenarios * removed old samples * republished updated samples
This commit is contained in:
Родитель
700312c775
Коммит
a1cff0b28f
|
@ -62,11 +62,14 @@ export async function main() {
|
|||
`Created queue ${queueClient.name} successfully, service assigned request ID: ${createQueueResponse.requestId}`
|
||||
);
|
||||
|
||||
// Send a message into the queue using the sendMessage method.
|
||||
const enqueueQueueResponse = await queueClient.sendMessage("Hello World!");
|
||||
console.log(
|
||||
`Sent message successfully, service assigned message ID: ${enqueueQueueResponse.messageId}, service assigned request ID: ${enqueueQueueResponse.requestId}`
|
||||
);
|
||||
// Send three messages into the queue using the sendMessage method.
|
||||
const messages = ["First message", "Second Message", "Third Message"];
|
||||
for (let i = 0; i < messages.length; i++) {
|
||||
const enqueueQueueResponse = await queueClient.sendMessage(messages[i]);
|
||||
console.log(
|
||||
`Sent message successfully, service assigned message ID: ${enqueueQueueResponse.messageId}, service assigned request ID: ${enqueueQueueResponse.requestId}`
|
||||
);
|
||||
}
|
||||
|
||||
// Peek a message using peekMessages method.
|
||||
const peekQueueResponse = await queueClient.peekMessages();
|
||||
|
@ -89,6 +92,22 @@ export async function main() {
|
|||
);
|
||||
}
|
||||
|
||||
// You can also receive a batch of messages (up to 32) in one call by specifying options.numberOfMessages.
|
||||
const batchDequeueResponse = await queueClient.receiveMessages({ numberOfMessages: 2 });
|
||||
if (batchDequeueResponse.receivedMessageItems.length == 2) {
|
||||
for (let i = 0; i < batchDequeueResponse.receivedMessageItems.length; i++) {
|
||||
const dequeueMessageItem = batchDequeueResponse.receivedMessageItems[i];
|
||||
console.log(`Processing & deleting message with content: ${dequeueMessageItem.messageText}`);
|
||||
const deleteMessageResponse = await queueClient.deleteMessage(
|
||||
dequeueMessageItem.messageId,
|
||||
dequeueMessageItem.popReceipt
|
||||
);
|
||||
console.log(
|
||||
`Deleted message successfully, service assigned request ID: ${deleteMessageResponse.requestId}`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Delete the queue.
|
||||
const deleteQueueResponse = await queueClient.delete();
|
||||
console.log(
|
||||
|
|
|
@ -28,8 +28,8 @@
|
|||
},
|
||||
"homepage": "https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/storage/storage-queue",
|
||||
"dependencies": {
|
||||
"@azure/storage-queue": "latest",
|
||||
"dotenv": "latest",
|
||||
"@azure/identity": "^2.0.1"
|
||||
"@azure/identity": "^2.0.1",
|
||||
"@azure/storage-queue": "^12.8.0",
|
||||
"dotenv": "latest"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -60,11 +60,14 @@ async function main() {
|
|||
`Created queue ${queueClient.name} successfully, service assigned request ID: ${createQueueResponse.requestId}`
|
||||
);
|
||||
|
||||
// Send a message into the queue using the sendMessage method.
|
||||
const enqueueQueueResponse = await queueClient.sendMessage("Hello World!");
|
||||
console.log(
|
||||
`Sent message successfully, service assigned message ID: ${enqueueQueueResponse.messageId}, service assigned request ID: ${enqueueQueueResponse.requestId}`
|
||||
);
|
||||
// Send three messages into the queue using the sendMessage method.
|
||||
const messages = ["First message", "Second Message", "Third Message"];
|
||||
for (let i = 0; i < messages.length; i++) {
|
||||
const enqueueQueueResponse = await queueClient.sendMessage(messages[i]);
|
||||
console.log(
|
||||
`Sent message successfully, service assigned message ID: ${enqueueQueueResponse.messageId}, service assigned request ID: ${enqueueQueueResponse.requestId}`
|
||||
);
|
||||
}
|
||||
|
||||
// Peek a message using peekMessages method.
|
||||
const peekQueueResponse = await queueClient.peekMessages();
|
||||
|
@ -87,6 +90,22 @@ async function main() {
|
|||
);
|
||||
}
|
||||
|
||||
// You can also receive a batch of messages (up to 32) in one call by specifying options.numberOfMessages.
|
||||
const batchDequeueResponse = await queueClient.receiveMessages({ numberOfMessages: 2 });
|
||||
if (batchDequeueResponse.receivedMessageItems.length == 2) {
|
||||
for (let i = 0; i < batchDequeueResponse.receivedMessageItems.length; i++) {
|
||||
const dequeueMessageItem = batchDequeueResponse.receivedMessageItems[i];
|
||||
console.log(`Processing & deleting message with content: ${dequeueMessageItem.messageText}`);
|
||||
const deleteMessageResponse = await queueClient.deleteMessage(
|
||||
dequeueMessageItem.messageId,
|
||||
dequeueMessageItem.popReceipt
|
||||
);
|
||||
console.log(
|
||||
`Deleted message successfully, service assigned request ID: ${deleteMessageResponse.requestId}`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Delete the queue.
|
||||
const deleteQueueResponse = await queueClient.delete();
|
||||
console.log(
|
||||
|
|
|
@ -32,9 +32,9 @@
|
|||
},
|
||||
"homepage": "https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/storage/storage-queue",
|
||||
"dependencies": {
|
||||
"@azure/storage-queue": "latest",
|
||||
"dotenv": "latest",
|
||||
"@azure/identity": "^2.0.1"
|
||||
"@azure/identity": "^2.0.1",
|
||||
"@azure/storage-queue": "^12.8.0",
|
||||
"dotenv": "latest"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^12.0.0",
|
||||
|
|
|
@ -24,15 +24,15 @@ export async function main() {
|
|||
const pipeline = newPipeline(sharedKeyCredential, {
|
||||
// httpClient: MyHTTPClient, // A customized HTTP client implementing IHttpClient interface
|
||||
retryOptions: {
|
||||
maxTries: 4
|
||||
maxTries: 4,
|
||||
}, // Retry options
|
||||
userAgentOptions: {
|
||||
userAgentPrefix: "BasicSample V10.0.0"
|
||||
userAgentPrefix: "BasicSample V10.0.0",
|
||||
}, // Customized telemetry string
|
||||
keepAliveOptions: {
|
||||
// Keep alive is enabled by default, disable keep alive by setting false
|
||||
enable: false
|
||||
}
|
||||
enable: false,
|
||||
},
|
||||
});
|
||||
|
||||
const queueServiceClient = new QueueServiceClient(
|
||||
|
|
|
@ -61,11 +61,14 @@ export async function main() {
|
|||
`Created queue ${queueClient.name} successfully, service assigned request ID: ${createQueueResponse.requestId}`
|
||||
);
|
||||
|
||||
// Send a message into the queue using the sendMessage method.
|
||||
const enqueueQueueResponse = await queueClient.sendMessage("Hello World!");
|
||||
console.log(
|
||||
`Sent message successfully, service assigned message ID: ${enqueueQueueResponse.messageId}, service assigned request ID: ${enqueueQueueResponse.requestId}`
|
||||
);
|
||||
// Send three messages into the queue using the sendMessage method.
|
||||
const messages = ["First message", "Second Message", "Third Message"];
|
||||
for (let i = 0; i < messages.length; i++) {
|
||||
const enqueueQueueResponse = await queueClient.sendMessage(messages[i]);
|
||||
console.log(
|
||||
`Sent message successfully, service assigned message ID: ${enqueueQueueResponse.messageId}, service assigned request ID: ${enqueueQueueResponse.requestId}`
|
||||
);
|
||||
}
|
||||
|
||||
// Peek a message using peekMessages method.
|
||||
const peekQueueResponse = await queueClient.peekMessages();
|
||||
|
@ -88,6 +91,22 @@ export async function main() {
|
|||
);
|
||||
}
|
||||
|
||||
// You can also receive a batch of messages (up to 32) in one call by specifying options.numberOfMessages.
|
||||
const batchDequeueResponse = await queueClient.receiveMessages({ numberOfMessages: 2 });
|
||||
if (batchDequeueResponse.receivedMessageItems.length == 2) {
|
||||
for (let i = 0; i < batchDequeueResponse.receivedMessageItems.length; i++) {
|
||||
const dequeueMessageItem = batchDequeueResponse.receivedMessageItems[i];
|
||||
console.log(`Processing & deleting message with content: ${dequeueMessageItem.messageText}`);
|
||||
const deleteMessageResponse = await queueClient.deleteMessage(
|
||||
dequeueMessageItem.messageId,
|
||||
dequeueMessageItem.popReceipt
|
||||
);
|
||||
console.log(
|
||||
`Deleted message successfully, service assigned request ID: ${deleteMessageResponse.requestId}`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Delete the queue.
|
||||
const deleteQueueResponse = await queueClient.delete();
|
||||
console.log(
|
||||
|
|
Загрузка…
Ссылка в новой задаче