本文整理汇总了PHP中Aws\Sqs\SqsClient::deleteMessageBatch方法的典型用法代码示例。如果您正苦于以下问题:PHP SqsClient::deleteMessageBatch方法的具体用法?PHP SqsClient::deleteMessageBatch怎么用?PHP SqsClient::deleteMessageBatch使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Aws\Sqs\SqsClient
的用法示例。
在下文中一共展示了SqsClient::deleteMessageBatch方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: deleteMessageBatch
protected function deleteMessageBatch($msgs)
{
$entries = [];
/** @var SqsReceivedMessage $bmsg */
foreach ($msgs as $idx => $bmsg) {
$entries[] = ["Id" => "buf_{$idx}", "ReceiptHandle" => $bmsg->getReceiptHandle()];
}
$result = $this->client->deleteMessageBatch(["QueueUrl" => $this->getQueueUrl(), "Entries" => $entries]);
if ($result['Failed']) {
foreach ($result['Failed'] as $failed) {
mwarning(sprintf("Deleting message failed, code = %s, id = %s, msg = %s, senderfault = %s", $failed['Code'], $failed['Id'], $failed['Message'], $failed['SenderFault']));
}
throw new \RuntimeException("Cannot delete some messages, consult log for more info!");
}
}
示例2: batchDelete
/**
* {@inheritDoc}
*/
public function batchDelete(array $jobs)
{
// SQS can only handle up to 10 jobs, so if we have more jobs, we handle them in slices
if (count($jobs) > 10) {
do {
$splicedJobs = array_splice($jobs, 0, 10);
$this->batchDelete($splicedJobs);
} while (count($splicedJobs) >= 10);
return;
}
// SQS throws an exception if no jobs are inserted, which can happen due to the slicing method
if (empty($jobs)) {
return;
}
$parameters = array('QueueUrl' => $this->queueOptions->getQueueUrl(), 'Entries' => array());
/** @var $job JobInterface */
foreach ($jobs as $key => $job) {
$jobParameters = array('Id' => $key, 'ReceiptHandle' => $job->getMetadata('receiptHandle'));
$parameters['Entries'][] = $jobParameters;
}
$this->sqsClient->deleteMessageBatch($parameters);
}
示例3: receiveMessages
public function receiveMessages($queueUrl, $maximalMessages = 1)
{
if ($maximalMessages > 10) {
throw new Exception('Messagenumber should be not more than 10');
}
$result = $this->service->receiveMessage(array('QueueUrl' => $queueUrl, 'MaxNumberOfMessages' => $maximalMessages));
$returnMessages = array();
$resultMessages = $result->getPath('Messages/*/Body');
if ($resultMessages != null) {
foreach ($resultMessages as $messageBody) {
// Do something with the message
//echo $messageBody;
$returnMessages[] = $messageBody;
}
$entrys = array();
$i = 0;
foreach ($result->getPath('Messages/*/ReceiptHandle') as $receiptHandle) {
$entrys[] = array('Id' => $i, 'ReceiptHandle' => $receiptHandle);
$i++;
}
$result = $this->service->deleteMessageBatch(array('QueueUrl' => $queueUrl, 'Entries' => $entrys));
}
return $returnMessages;
}