ChangeMessageVisibilityBatch 搭配 CLI 使用 - AWS SDK 程式碼範例

文件 AWS SDK AWS 範例 SDK 儲存庫中有更多可用的 GitHub 範例。

本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。

ChangeMessageVisibilityBatch 搭配 CLI 使用

下列程式碼範例示範如何使用 ChangeMessageVisibilityBatch

CLI
AWS CLI

以批次形式變更多個訊息的逾時可見性

此範例會將 2 個指定訊息的逾時可見性變更為 10 小時 (10 小時 * 60 分鐘 * 60 秒)。

命令:

aws sqs change-message-visibility-batch --queue-url https://sqs.us-east-1.amazonaws.com/80398EXAMPLE/MyQueue --entries file://change-message-visibility-batch.json

輸入檔案 (change-message-visibility-batch.json):

[ { "Id": "FirstMessage", "ReceiptHandle": "AQEBhz2q...Jf3kaw==", "VisibilityTimeout": 36000 }, { "Id": "SecondMessage", "ReceiptHandle": "AQEBkTUH...HifSnw==", "VisibilityTimeout": 36000 } ]

輸出:

{ "Successful": [ { "Id": "SecondMessage" }, { "Id": "FirstMessage" } ] }
PowerShell
for PowerShell 工具

範例 1:此範例會變更 2 則訊息的可見性逾時,並在指定的佇列中具有指定的接收控點。第一個訊息的可見性逾時會變更為 10 小時 (10 小時 * 60 分鐘 * 60 秒 = 36000 秒)。第二個訊息的可見性逾時會變更為 5 小時 (5 小時 * 60 分鐘 * 60 秒 = 18000 秒)。

$changeVisibilityRequest1 = New-Object Amazon.SQS.Model.ChangeMessageVisibilityBatchRequestEntry $changeVisibilityRequest1.Id = "Request1" $changeVisibilityRequest1.ReceiptHandle = "AQEBd329...v6gl8Q==" $changeVisibilityRequest1.VisibilityTimeout = 36000 $changeVisibilityRequest2 = New-Object Amazon.SQS.Model.ChangeMessageVisibilityBatchRequestEntry $changeVisibilityRequest2.Id = "Request2" $changeVisibilityRequest2.ReceiptHandle = "AQEBgGDh...J/Iqww==" $changeVisibilityRequest2.VisibilityTimeout = 18000 Edit-SQSMessageVisibilityBatch -QueueUrl https://sqs.us-east-1.amazonaws.com/80398EXAMPLE/MyQueue -Entry $changeVisibilityRequest1, $changeVisibilityRequest2

輸出:

Failed Successful ------ ---------- {} {Request2, Request1}