diff --git a/src/Sqs/Queue.php b/src/Sqs/Queue.php index 1ffd7e2..ed3e938 100644 --- a/src/Sqs/Queue.php +++ b/src/Sqs/Queue.php @@ -57,10 +57,14 @@ public function pop($queue = null) { $queue = $this->getQueue($queue); - $response = $this->sqs->receiveMessage([ + $options = [ 'QueueUrl' => $queue, - 'AttributeNames' => ['ApproximateReceiveCount'], - ]); + ]; + + $options = $this->addAttributeNames($options); + $options = $this->addMessageAttributeNames($options); + + $response = $this->sqs->receiveMessage($options); if (isset($response['Messages']) && count($response['Messages']) > 0) { $queueId = explode('/', $queue); @@ -80,6 +84,39 @@ public function pop($queue = null) } } + private function addAttributeNames($options) + { + $list = Config::get('sqs-plain.popAttributeNames', ''); + $names = array_merge(['ApproximateReceiveCount'], explode(',', $list)); + + $options['AttributeNames'] = $this->cleanArray($names); + + return $options; + } + + private function addMessageAttributeNames($options) + { + $list = Config::get('sqs-plain.popMessageAttributeNames', ''); + + if (empty($list)) { + return $options; + } + + $names = explode(',', $list); + + $options['MessageAttributeNames'] = $this->cleanArray($names); + + return $options; + } + + private function cleanArray($array) + { + $array = array_map('trim', array_filter($array)); + $array = array_unique($array); + + return $array; + } + /** * @param string|array $payload * @param string $class