ChangeMessageVisibilityBatch与 a 一起使用 CLI - AWS SDK代码示例

AWS 文档 AWS SDK示例 GitHub 存储库中还有更多SDK示例

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

ChangeMessageVisibilityBatch与 a 一起使用 CLI

以下代码示例演示如何使用 ChangeMessageVisibilityBatch

CLI
AWS CLI

批量更改多条消息的超时可见性

此示例将 2 条指定消息的超时可见性更改为 10 小时(10 小时 x 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
用于 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}