AWS 文檔 AWS SDK示例 GitHub 回購中有更多SDK示例
本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
搭ChangeMessageVisibilityBatch
配 AWS SDK或使用 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
--entriesfile://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" } ] }
-
如需詳API細資訊,請參閱AWS CLI 指令參考ChangeMessageVisibilityBatch
中的。
-
- PowerShell
-
- 適用的工具 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}
-
如需詳API細資訊,請參閱AWS Tools for PowerShell 指令程ChangeMessageVisibilityBatch式參考中的。
-
ChangeMessageVisibility
CreateQueue