Skip to content

Commit

Permalink
Add new QueueClient::getAllMessages() method
Browse files Browse the repository at this point in the history
  • Loading branch information
bartoszwidera committed Feb 29, 2024
1 parent 6e53640 commit fd6bfbd
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/Aws/Sqs/SqsQueue.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 [];
}
}
5 changes: 5 additions & 0 deletions src/Memory/Queue/MemoryQueueClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
1 change: 1 addition & 0 deletions src/Queue/QueueClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

0 comments on commit fd6bfbd

Please sign in to comment.