diff --git a/src/Aws/Sqs/SqsQueue.php b/src/Aws/Sqs/SqsQueue.php index 9894542..cd265bd 100644 --- a/src/Aws/Sqs/SqsQueue.php +++ b/src/Aws/Sqs/SqsQueue.php @@ -59,4 +59,20 @@ public function getMessages(int $numberOfMessages = 10): array return []; } + + public function getAllMessages(): array + { + $response = $this->client->receiveMessage([ + 'QueueUrl' => sprintf('%s/%s', $this->queueEndpoint, $this->queueName), + ]); + + if (is_array($response->search('Messages'))) { + return array_map( + static fn ($message) => $message['Body'], + $response->search('Messages') + ); + } + + return []; + } } diff --git a/src/Memory/Queue/MemoryQueueClient.php b/src/Memory/Queue/MemoryQueueClient.php index 288bac5..db47ea1 100644 --- a/src/Memory/Queue/MemoryQueueClient.php +++ b/src/Memory/Queue/MemoryQueueClient.php @@ -31,4 +31,9 @@ public function getMessages(int $numberOfMessages = 10): array { return array_splice($this->memory, 0, $numberOfMessages); } + + public function getAllMessages(): array + { + return $this->memory; + } } diff --git a/src/Queue/QueueClient.php b/src/Queue/QueueClient.php index d1c568d..0185d4c 100644 --- a/src/Queue/QueueClient.php +++ b/src/Queue/QueueClient.php @@ -7,4 +7,5 @@ interface QueueClient { public function sendMessage(Message $message, MessageMetadata $metadata): void; public function getMessages(int $numberOfMessages = 10): array; + public function getAllMessages(): array; }