From 23946eb0c9a8759170cb5d1254e4ccd2de77b389 Mon Sep 17 00:00:00 2001 From: Dirk Tepe Date: Sun, 25 Aug 2019 21:32:56 -0400 Subject: [PATCH 1/2] Add configurable job attribute names --- src/Sqs/Queue.php | 43 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 40 insertions(+), 3 deletions(-) diff --git a/src/Sqs/Queue.php b/src/Sqs/Queue.php index 1ffd7e2..0f3ee3c 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.attributeNames', ''); + $names = array_merge(['ApproximateReceiveCount'], explode(',', $list)); + + $options['AttributeNames'] = $this->cleanArray($names); + + return $options; + } + + private function addMessageAttributeNames($options) + { + $list = Config::get('sqs-plain.messageAttributeNames', ''); + + 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 From 5093c7dd6e68e0dc6f0370e247328e2b314bd49f Mon Sep 17 00:00:00 2001 From: Dirk Tepe Date: Sun, 25 Aug 2019 21:45:31 -0400 Subject: [PATCH 2/2] Use pop specific configuration item names --- src/Sqs/Queue.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Sqs/Queue.php b/src/Sqs/Queue.php index 0f3ee3c..ed3e938 100644 --- a/src/Sqs/Queue.php +++ b/src/Sqs/Queue.php @@ -86,7 +86,7 @@ public function pop($queue = null) private function addAttributeNames($options) { - $list = Config::get('sqs-plain.attributeNames', ''); + $list = Config::get('sqs-plain.popAttributeNames', ''); $names = array_merge(['ApproximateReceiveCount'], explode(',', $list)); $options['AttributeNames'] = $this->cleanArray($names); @@ -96,7 +96,7 @@ private function addAttributeNames($options) private function addMessageAttributeNames($options) { - $list = Config::get('sqs-plain.messageAttributeNames', ''); + $list = Config::get('sqs-plain.popMessageAttributeNames', ''); if (empty($list)) { return $options;