Skip to content

Bug: SQS uses incorrect timestamp property #1402

@mroeling

Description

@mroeling

See https://docs.aws.amazon.com/AWSSimpleQueueService/latest/APIReference/API_Message.html

in code:

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

        return null === $value ? null : (int) $value;
    }

But in the SQS message, it should be the SentTimestamp property. As it is atm, this will allways lead to null as value for getTimestamp().

Proposed fix for SQSMessage.php:

    public function getTimestamp(): ?int
    {
            $attributes = $message->getAttributes();
            if (isset($attributes['SentTimestamp'])) {
                $sentTimestamp = (int) $attributes['SentTimestamp'];
                if ($sentTimestamp > 0) {
                    // SQS SentTimestamp is milliseconds since epoch.
                    return intdiv($sentTimestamp, 1000);
                }
            }
            return null;
    }

EDIT: PR slightly different to use available methods instead

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions