本文整理汇总了PHP中Aws\Sqs\SqsClient::receiveMessage方法的典型用法代码示例。如果您正苦于以下问题:PHP SqsClient::receiveMessage方法的具体用法?PHP SqsClient::receiveMessage怎么用?PHP SqsClient::receiveMessage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Aws\Sqs\SqsClient
的用法示例。
在下文中一共展示了SqsClient::receiveMessage方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: receiveMessage
/**
* @return MessageReceivedInterface[]
* @see https://docs.aws.amazon.com/aws-sdk-php/v3/api/api-sqs-2012-11-05.html#receivemessage
*/
public function receiveMessage(array $options = [])
{
$this->params = $this->mergeParams([], $options);
$sqsResult = $this->awsSqsClient->receiveMessage($this->params);
$sqsMessages = empty($sqsResult['Messages']) ? [] : $sqsResult['Messages'];
return $this->createMessageObject($sqsMessages);
}
示例2: pop
/**
* Pop the next job off of the queue.
*
* @param string $queue
* @return \Illuminate\Contracts\Queue\Job|null
*/
public function pop($queue = null)
{
$queue = $this->getQueue($queue);
$response = $this->sqs->receiveMessage(['QueueUrl' => $queue, 'AttributeNames' => ['ApproximateReceiveCount']]);
if (count($response['Messages']) > 0) {
return new SqsJob($this->container, $this->sqs, $queue, $response['Messages'][0]);
}
}
示例3: dequeue
/**
* {@inheritdoc}
*/
public function dequeue(SerializerInterface $serializer)
{
$message = $this->client->receiveMessage(['QueueUrl' => $this->url])->get('Messages');
if (count($message)) {
return new SqsJob($this->client, $this->url, $message[0]['ReceiptHandle'], $serializer->unserialize($message[0]['Body']));
}
return null;
}
示例4: pop
/**
* Pop the next job off of the queue.
*
* @param string $queue
* @return \Illuminate\Queue\Jobs\Job|null
*/
public function pop($queue = null)
{
$queue = $this->getQueue($queue);
$response = $this->sqs->receiveMessage(array('QueueUrl' => $queue));
if (count($response['Messages']) > 0) {
return new SqsJob($this->container, $this->sqs, $queue, $response['Messages'][0]);
}
}
示例5: dequeue
public function dequeue()
{
$result = $this->client->receiveMessage(array('QueueUrl' => $this->queueUrl));
$messages = $result->get('Messages');
if (!$messages) {
return false;
}
return array($messages[0]['Body'], $messages[0]['ReceiptHandle'], []);
}
示例6: pop
/**
* @inheritdoc
*/
public function pop($queue)
{
$response = $this->sqs->receiveMessage(['QueueUrl' => $queue]);
if (empty($response['Messages'])) {
return false;
}
$data = reset($response['Messages']);
return ['id' => $data['MessageId'], 'body' => $data['Body'], 'queue' => $queue, 'receipt-handle' => $data['ReceiptHandle']];
}
示例7: receive
/**
* @throws \RuntimeException
*
* @return MessageInterface
*/
public function receive()
{
$packer = $this->getPacker();
if (!$packer) {
throw new \RuntimeException('Packed not defined');
}
$message = $this->client->receiveMessage(array('QueueUrl' => $this->queueUrl));
return $packer->decode($message);
}
示例8: fetchJob
/**
* Return next job from the queue.
* @return Job|boolean the job or false if not found.
*/
public function fetchJob()
{
$message = $this->_client->receiveMessage(['QueueUrl' => $this->url, 'AttributeNames' => ['ApproximateReceiveCount'], 'MaxNumberOfMessages' => 1]);
if (isset($message['Messages']) && count($message['Messages']) > 0) {
return $this->createJobFromMessage($message['Messages'][0]);
} else {
return false;
}
}
示例9: receiveSqsMessage
/**
* @param mixed[] $args
* @return Result
* @throws ExceptionInterface
*/
private function receiveSqsMessage(array $args = [])
{
$result = $this->sqsClient->receiveMessage($args);
$messages = array();
foreach ($result->search('Messages[]') as $i => $message) {
$messages[$i] = $this->decodeSqsMessage($message);
}
$result->offsetSet('Messages', $messages);
return $result;
}
示例10: receive
/**
* {@inheritDoc}
*/
public function receive()
{
$result = $this->client->receiveMessage(array('QueueUrl' => $this->queueUrl));
if (null === $result->get('Messages')) {
return;
}
if ($result) {
return new Message($result['Messages'][0]['Body'], array('ReceiptHandle' => $result['Messages'][0]['ReceiptHandle']));
}
}
示例11: pull
/**
* Wait and get job from a queue
*
* @access public
* @return Job|null
*/
public function pull()
{
$result = $this->sqsClient->receiveMessage(array('QueueUrl' => $this->sqsUrl, 'WaitTimeSeconds' => empty($this->config['LongPollingTime']) ? 0 : (int) $this->config['LongPollingTime']));
if ($result['Messages'] == null) {
return null;
}
$resultMessage = array_pop($result['Messages']);
$job = new Job();
$job->setId($resultMessage['ReceiptHandle']);
$job->unserialize($resultMessage['Body']);
return $job;
}
示例12: receive
/**
* Receive messages
*
* @param bool $priority
* @param int $num
* @param int $wait
* @return \Guzzle\Service\Resource\Model
*/
public function receive($priority = false, $num = 10, $wait = 20)
{
if (empty($this->url)) {
return false;
}
$receiveData = ['QueueUrl' => $this->url, 'MaxNumberOfMessages' => $num, 'WaitTimeSeconds' => $wait];
if ($priority) {
$receiveData['MessageAttributeNames'] = ["Priority"];
}
$result = $this->client->receiveMessage($receiveData);
return $result->toArray();
}
示例13: receive
/**
* @param int $messagesCount
* @return array of QueueMessage
*/
public function receive($messagesCount = 1)
{
$result = $this->client->receiveMessage(['QueueUrl' => $this->queueUrl, 'WaitTimeSeconds' => 20, 'VisibilityTimeout' => 3600, 'MaxNumberOfMessages' => $messagesCount]);
$queueUrl = $this->queueUrl;
return array_map(function ($message) use($queueUrl) {
$body = json_decode($message['Body']);
if (!is_object($body)) {
$this->client->deleteMessage(['QueueUrl' => $queueUrl, 'ReceiptHandle' => $message['ReceiptHandle']]);
throw new ApplicationException("Corrupted message {$message['MessageId']} received. Message was deleted from SQS.", null, ['message' => $message]);
}
return new QueueMessage($message['MessageId'], $body, $message['ReceiptHandle'], $queueUrl);
}, (array) $result['Messages']);
}
示例14: dequeue
/**
* @inheritDoc
*/
public function dequeue($queueName)
{
$queueUrl = $this->getQueueUrl($queueName);
$result = $this->client->receiveMessage(array('QueueUrl' => $queueUrl, 'MaxNumberOfMessages' => 1, 'AttributeNames' => ['ApproximateReceiveCount']));
if (!$result || !($messages = $result['Messages'])) {
return null;
}
$message = array_shift($messages);
$wrapped = $this->unserialize($message['Body']);
$msg = new DefaultEnvelope($wrapped->unwrap(), $message['Attributes']['ApproximateReceiveCount']);
$env = new SqsEnvelope($message['MessageId'], $msg, $message['ReceiptHandle']);
return $env;
}
示例15: receiveMessageBatch
/**
* @param int $max_count
* @param int $wait
* @param int $visibility_timeout
* @param array $metas
* @param array $message_attributes
*
* @return SqsReceivedMessage[]
*/
protected function receiveMessageBatch($max_count = 1, $wait = null, $visibility_timeout = null, $metas = [], $message_attributes = [])
{
if ($max_count > 10 || $max_count < 1) {
throw new \InvalidArgumentException("Max count for SQS message receiving is 10");
}
$args = ["QueueUrl" => $this->getQueueUrl(), "MaxNumberOfMessages" => $max_count];
if ($wait !== null && is_int($wait)) {
$args['WaitTimeSeconds'] = $wait;
}
if ($visibility_timeout !== null && is_int($visibility_timeout)) {
$args['VisibilityTimeout'] = $visibility_timeout;
}
if ($metas && is_array($metas)) {
$args['AttributeNames'] = $metas;
}
if ($message_attributes && is_array($message_attributes)) {
$args['MessageAttributeNames'] = $message_attributes;
}
$result = $this->client->receiveMessage($args);
$messages = $result['Messages'];
if (!$messages) {
return [];
}
$ret = [];
foreach ($messages as $data) {
$msg = new SqsReceivedMessage($data);
$ret[] = $msg;
}
return $ret;
}