Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions pkg/sqs/SqsMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,10 @@ public function getMessageId(): ?string

public function getTimestamp(): ?int
{
$value = $this->getHeader('timestamp');
$value = $this->getAttribute('SentTimestamp');

return null === $value ? null : (int) $value;
// SQS SentTimestamp is milliseconds since epoch.
return null === $value ? null : (int) $intdiv($value, 1000);
}

public function setTimestamp(?int $timestamp = null): void
Expand Down
1 change: 1 addition & 0 deletions pkg/sqs/Tests/SqsConsumerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,7 @@ public function testShouldReceiveMessage()
'ApproximateReceiveCount' => '3',
'SentTimestamp' => '1560512260079',
], $result->getAttributes());
$this->assertSame(1560512260, $result->getTimestamp());
$this->assertTrue($result->isRedelivered());
$this->assertEquals('The Receipt', $result->getReceiptHandle());
$this->assertEquals('theMessageId', $result->getMessageId());
Expand Down
17 changes: 17 additions & 0 deletions pkg/sqs/Tests/SqsMessageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,23 @@ public function testShouldSetTimestampAsHeader()
$this->assertSame(['timestamp' => 12345], $message->getHeaders());
}

public function testShouldGetTimestampFromSentTimestampAttribute()
{
$message = new SqsMessage();
$message->setAttributes([
'SentTimestamp' => '1560512260079',
]);

$this->assertSame(1560512260, $message->getTimestamp());
}

public function testShouldReturnNullTimestampWhenSentTimestampAttributeIsMissing()
{
$message = new SqsMessage();

$this->assertNull($message->getTimestamp());
}

public function testShouldSetReplyToAsHeader()
{
$message = new SqsMessage();
Expand Down