我试图一次删除AWS SQS
批处理消息,删除数组块的第一个10
消息但不删除第二个块,抛出错误
AWS.SimpleQueueService.TooManyEntriesInBatchRequest(客户端):最大值 每个请求的条目数为10.您已发送12。
我正在执行这些步骤。
我有12条消息的数组,并将它们转换为这样的块
$chunks = array_chunk($entries, 10, true); // make chunks of 10 items per array
第1块
Array
(
[0] => Array
(
[Id] => 85d6aea0-7903-41d4-8f5a-efba992e8868
[ReceiptHandle] => AQEBRW1MH1XnKD0WMLl1xtJqLpJSeEpgephGcaRTqzz+FdOAXOnYMTcG46+SpNp79cDoH1vnxPswcpuk5lK9HpHaBe8jMx3ILliCPnDieSamD84H0gz+hMgqRauqjw6jTZ/r+vkF+1AzIKo7JcxlG4IqIFXkoQCQlAsdBqALlQbb3y9aSwv9ZrBCc74x+4b7r8TvagFEbN4O984N7/wRh9AvMV/n4MrESePKjOtks53ACBPTf6c4AuBNrnbOvLCABV10KoDRpHhSC9bxQPbR/gM814+utyvRKEjk5kS0sAtUzcmgVkms/iS5vF70ImiVlWnaA2TO82G34zA9g52rRRxeSdpp+LTwMMNPExCxb1TLgyVGp1ROPfwzK7woXMDvmXaHVfVTbp/hLVCLA3O6x2U7aw==
)
[1] => Array
(
[Id] => 1f2f5165-56a1-4df4-a70a-d22869b408ec
[ReceiptHandle] => AQEBJlSHjWdNtHzY3WtGpJW+0IQkoF51Pq+hookKBbc9oGTPsm1h9Nm+Y6BphhgbXzAHDpRoOPc7OSQEBOEYC4l4vjgXmOHHVve6lfQqPcZd3zhdFJzy5ZWgP00WIzurOi55j+EHaFRBS1SEx6Tj6rx4AJ/Nuvri8hmBYctbyQzhZKgIVYdviTXhkxzdWHsZ2zduWHU5AWex3Z+xgH3xTrRPUoO7Bsqun+QHS0lqS93D6TejHnhKGJO3Q5cUJA0Lo0iEF9rND4ha0Ar9hyAGseGwqHjQYr0279x1e5KuVnRip6pj3WBiLW7CjW3+XqRLRFSaquIHMqUwp4HcamTjUNSzMFhtHRPRi1w28+tPQ3bswV6b3YMXFc40NQzHzQVn5y/839+xk00UlIKe9SIh9qYecQ==
)
[2] => Array
(
[Id] => 726b8b47-be1f-4aea-aa30-f24d08361d52
[ReceiptHandle] => AQEBHYsYOYJZJV4dMvzprs2v/r3+SGQoxaEYvIfHpwvHkHpPZ7hIgGfhEpZ8mfSJs7iAKETt5KEuyWTbEvIhijX2SjPOWOXZgkvkZ0yAR/sTnLNng3ZwvP7qsLL50FjBBDgAyRCeN0LMdZJ4LApTdCAaeU+5XOnEgpImBeclp7rzlfONofsyyLl7ifuozfzdWz0PhAsIUqLaQzxzvKbOBBZt6lgVgGGDucuduMpcxugarr71N/IGHt00orJMFRhkorvIoNxp1FFbUzFM0izX8Z5/lghFywbXBafoc8TMGp4L+K7ZPRB/T7NNGUKEtTBydbOk2KoQXfFoshV15LE5zT/NLt9UVHbZsjl1yUofxolqEnH0xpi2KCbJXttImaTK7TXI2CzG1ZK0KdBLCGnaCKW7ZA==
)
[3] => Array
(
[Id] => ed365b40-d6c7-4e8a-afd1-9489a8e4706a
[ReceiptHandle] => AQEBUW6iS/PXNzxciJL2rikTumcgmbVM+aILQQQ99/XxBgOtV+LY6y1qCcbH1TRqk8hv0wzihN/JUnXxik40eF0xHtwMjiay7uFsuAAhorGIh7376IgqK+pPNpHtTjcABCIalt1C2MiugSgy0D3sxyis0pDz7GuN7oVxfvppVPVpnS/3i59WszsiHhNoNEtW3xAZ9EOY3qIlIEG0caPCKPfEAJf9kAUfTPSB45lUve8sjcDk2EGRp0BiwnJ4SYceQLU4eVc2VRky9znK7iDIbCyzWfopnMrjk5zONTcXIa0KixJXlsOzUUdPETMt5WafXUHc3vrvLb7g3zWEo9+W+NeJ4ODwGKrWlBh75ckdIb7ZuADtstINkgfBwTNMOgox+Z9Qi45iJNb3TvHFEFSZ6BUuuw==
)
[4] => Array
(
[Id] => 48c4f212-1375-40f0-abcc-1247bef9b89d
[ReceiptHandle] => AQEB/xROTQvGFdWzP1tUAt75os/f29QzJ1OdXJzIV/24/MmE0HXJlZwAg4EwbO+OQ8EATvrSxJYeO5Y11WToOcTM194f5AnJ1mL2Ul3Zom3OmeiDEqptUz5NsM9jOPQaf/gaHr0V7++8gCosn2UO5+21DdYy0WfAEL3U1gAgB2z5IN/HPQnXg7h5JyxRE/o7BMWs+doAdk/sl5Y82qp1MRVAS8/t6uVF/JTlaPmaeMfeysMKmOEe+OnSibYX0P+KzOzwfC4GmNDh6wepmsZ1PG9IMoKik0bYa0FxFJfPYO81wEtihEqOVUFj8vv+msSRZ+J+uFNCS7ikdAJMWnL0w7AJfj4jWgK5TcThUmjWa9XY40kcNCv0jEiKQwh9S84koPucwbn9ZqRUvtcOD+xXJJiEuQ==
)
[5] => Array
(
[Id] => 604db975-48da-48ab-bd43-334c67cd8450
[ReceiptHandle] => AQEBdoaZFWmTiFmbG7HrX6RoOLTDb45Fsyo6VEgDZb+x01glh4ewQ12emwzSAXsoodM5jP5NOGsqACFxY1rgUFsKP4S2Qi2pEw80X1BwXfrETTp2axwLlrws9I5YoHXqm+D/tJRlSc6whQqS6S1hRnWYAVaTllDDi+zDvi+3dBnStmgRmF3V3FTc8VJZ6PGdrd4UF3UpMzUylQhQndf/vxnnUI6qXd7IjOSZLwoohr0jYRLUSc4QZrp4T4itFgYF4kVSLtB7HCvUhdWt90zR8n4QW7WbTHfhOxRD9gIelFmzl/ssjS85eZ+ZnIxSZiJnJ13DGGNBo5POOHXqk0MOqC7dYzyaW+NOC/C2pBD2XkjG0fDStftb5KuAo+tjtMfCvJAEOtqAQsRXVb9/MN/zhAEPSA==
)
[6] => Array
(
[Id] => e8525043-7011-4d2b-965e-a844f21ade81
[ReceiptHandle] => AQEBzJZiFcePez9hVhoUmY4ccH758aIfxwM0QkUmIoPlrvyPJGOsQT9GeSPVCjYhCBVlMikj/VohnfANAS0puVsAxwR8sMxhZhrALg2D2nnY2u40d3ktM7YKLhut/FQLxSw7OEqo3NoW3akQdusuWSYKRkb6aLICYhLfJch2x7BPaUFxB6gM4PkPZj9yeocX8KP2+TMPPmT6lESGmq1TjDIXmw0A+eFIWEOr/5k66wbGhDUArrglqKlhJgI15k8k4f5W11LGEJUPVWazzUoCHhzmXiEB3hvfzlzKRQwhdZqM4YHAVZsqrPfcQth3dpdGW6p8yEaco+yBJ13rNZD7EYGARpzMSK3WEU18zbc33SphPHVPewYgtrqNCFev2L/Wfe3mpEN13FLNbUrU1cFRrd7xSw==
)
[7] => Array
(
[Id] => 30ec6108-e3c3-4348-b449-00775f18e579
[ReceiptHandle] => AQEBOGx1ntCVZUGvNvqmk9IQZTUOXa5XTYYlMQatmWEOX0GKfNSq4P1hOcFWgEAhp3C7hFyaTrV+8w5+r+evw6+A80JV1ZKwlSTCti7riYXz7cJDsU6HXvIwrrzZmCBLc1WH6kR983Hi/H9pHqeaB1nOlRLG6jUiQKlLdAVQHVGIDXqmuALGLMTIOiOIzZmcnqhbKiHVJ53lggi/6CCSLe75ofSrFf/dAZCABi8pkuFceOJdcQ8M3qUuwehR879784cnLDVADq6QeEqB9acxINra/MKOo+YyUP0My+49yRJJhjb1vORy3HV56ZsZGNf8tWHuqBSI1aTpPgCUKVGLlId61LHjXMIYlv6e1myY5imt5RLOLleLTq0vQxGtU1bjL+ixOdzLqC571uOIgyEvLkz47Q==
)
[8] => Array
(
[Id] => 06d0c6a5-d266-4f64-8c1a-fcb12e94d1aa
[ReceiptHandle] => AQEB8d+rJyCEGFfw9zNh4lCS1MNxDC9Zdk6ARJjH7ff9gnZzcwWFvuq5JwsWaItY11dDFWowbzY6Xk1Jg4ii2RvViAqEg86dSfK9N0WstWe4yRYv0thVqSv1BuESymoSnaljcmamh6HfxuFHwkiyYFTtc2oJ3YRrWMlAYaSj8cviZPTLb7Q1zc47UlTfEGdpC4KSQ65mPg4ZutlbZQtEzXRZtwMbNm4tFciKBVpK+5N1NcNTi5S+6Nd4stS14q/a928urssO/Gewh7tDXXndZ3PtCEqGKC18xHHMenY5g2xhZT6NsZxu8+lPX8WMS9HB+lwbZeYBWNu/zqSPop/UXJrXSzHIda3beYl1N11vDAXWnfDS1vYOev4NQkeuOVJd6XJso6hGDo7cb/CEtwzwynw19Q==
)
[9] => Array
(
[Id] => 36563e1b-a4a7-4d65-ad89-d5357d1c06a6
[ReceiptHandle] => AQEB0d//nx/AQGOrERVynoRxtbwaerPNHy6vurGAzJ+S7FMf0X5HS3BGNVkUk57GhssgcAiQ1XJ/8iqaZ3NVlER3OXttgjME2bYz+ji/ermvAZCazmP6DsQSqh7caGxIR1HcsAsXksp3nRefEbqoziBPH15xXyhP45SiE6xLBsiIbvP10JMPmDXbhVRBugMf3lYNrXP55ZKf8O0Nm+DrSmk2mckevwugY0SmiGIjwV5+uOIIoKsen37WU0mnDX883jji4GH+TWyE95wHlzRvSa2OZdMWt4s66tyTyVo3U5Ji/9RyUhceNQJZxyKUf68WBeOiymd1TVwzkiJhdmXb5wSteOcZZX2oH+feyOeOBxPwpKbK05ttBNVdf3IayJQvbtUu4q58dkLDdOnJH+m/MC+vyA==
)
)
第2块
Array
(
[10] => Array
(
[Id] => 1f2f5165-56a1-4df4-a70a-d22869b408ec
[ReceiptHandle] => AQEByG1UiIz/+Uqlb3R5gkfVqOzNrWPYq8YEc3XluoqYJpVQD13TcpeFAPNU4C0NybzsKtRLLQfsM58dUehrlGP5JmU9H+ROgAGDF5R6qVNyot+dJtRKmUJdmt2A2r6NkiYMg7hgrU4+upRMhTlOAY/Ni5HGOvJbhvR/upHKSVe5gWoabQTG6Puvvg8L/pamET+PcImDxQPgSNzLc9L/8SwhTwYyqdYG4CwhymelqiAtI7siHpyBBmC24JyX6IWL/3pJenI0yBZhREdNsd2hHLcZAWoCrhq4EFsneAgcnm9UWOCuorceCOQHU94trl38z9tbXXbpEjI5ZVWlrhc6Abx6vknegjIdAoR2gLwkvUdSTHkV4QxoFZOKjLoYJBeV2ugaHgJi/52/DdL9HNQoQziwZg==
)
[11] => Array
(
[Id] => 726b8b47-be1f-4aea-aa30-f24d08361d52
[ReceiptHandle] => AQEBcWCMm29Cic5pJH+1I0ppsiQxjQw9Q0znj26PZ2P1YQqu5tMvTsCX6t63JgoYvxzH34Ss6oXxzuXe8vXiIVoj7kSFiZdBnPVq+tcEoEFnCfBOtg2WQVONWlN5JYulAIewxXbQS2JZJjIu4HWHHzhS0oRw62OMz325/pbcuaW2a1mfU+Zs7bF9eK6AOCl4RJ0VBACSodpNJtlyqOxnS7C6zkuuVERGuQIxhFFTx44pAHzvQ3+WklGkY05QNNdxUaGzvQGhqzlwFiPwhBi6Cg22PgrSwnSt8Aef1azykibngUP035LOi1ig6Tc5jrWFX39MN+UYt6AVBTELxv4uTIi1VFJue8f8mRxJSL4H+YQH0BBy/zxPAJZANK4E066jbxtgffk8ktJcZOGBCUuFeFSrVA==
)
)
然后遍历条目并进行删除操作
//loop through and delete one by one
foreach($chunks as $k=>$entry_chunk){
$result = $this->Sqs->deleteMessageBatch([
'Entries' => $entry_chunk,
'QueueUrl' => $queueUrl
]);
}
这会删除第一个Chunks(10个项目),而第二个进入,它给我错误
AWS.SimpleQueueService.TooManyEntriesInBatchRequest(客户端):最大值 每个请求的条目数为10.您已发送12。
我如何一次删除多条消息?
答案 0 :(得分:0)
$chunks = array_chunk($entries, 10, true);
第三个论点似乎错了,因为这个,在第二个块中:
[10] => Array
第二个块的第0个元素不应该有索引10,是吗?应该是0.这似乎暗示在它之前有10个未定义的元素,所以你仍然显然试图在一个批次中删除12个消息... 10个无效,未定义的元素和剩下的2个。由于此错误,SQS可能无法告诉您前10条消息甚至没有意义,因为您已超出每个请求的最大消息数 - 即10 - 因此请求已无效
第三个参数$preserve_keys
设置为true
,但应为false
。
<强> preserve_keys 强>
设置为
TRUE
时,将保留密钥。默认值为FALSE
,它将以数字方式重新索引块