Skip to content

Commit

Permalink
Merge pull request #1690 from vmiguellima/add-get-queue-name-to-sqs-r…
Browse files Browse the repository at this point in the history
…ecord

Add ability to get queue name from sqs event
  • Loading branch information
mnapoli committed Nov 14, 2023
2 parents 2d49502 + 36aa475 commit 7545dbb
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/Event/Sqs/SqsRecord.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,17 @@ public function getReceiptHandle(): string
return $this->record['receiptHandle'];
}

/**
* Returns the name of the SQS queue that contains the message.
* Queue naming constraints: https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/quotas-queues.html
*/
public function getQueueName(): string
{
$parts = explode(':', $this->record['eventSourceARN']);

return $parts[count($parts) - 1];
}

/**
* Returns the record original data as an array.
*
Expand Down
18 changes: 18 additions & 0 deletions tests/Event/Sqs/SqsRecordTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php declare(strict_types=1);

namespace Bref\Test\Event\Sqs;

use Bref\Event\Sqs\SqsRecord;
use PHPUnit\Framework\TestCase;

class SqsRecordTest extends TestCase
{
public function test_it_can_get_queue_name_from_sqs_event()
{
$event = json_decode(file_get_contents(__DIR__ . '/sqs.json'), true);

$sqsRecord = new SqsRecord($event['Records'][0]);

$this->assertSame($sqsRecord->getQueueName(), 'my-queue');
}
}

0 comments on commit 7545dbb

Please sign in to comment.