Skip to content

Bug: SQS uses incorrect timestamp property #1402

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions