19/01/2022 - AWS
In this example we are going to move messages from AWS SQS source queue to DLQ after 3 retries. Retries happen if the messages are not processed for some reason. Message will be visible every 30 seconds between each attempts.
$ aws --profile localstack --endpoint-url http://localhost:4566 sqs create-queue \
--queue-name work-queue.dlq
$ aws --profile localstack --endpoint-url http://localhost:4566 sqs create-queue \
--queue-name work-queue \
--attributes '{"RedrivePolicy":"{\"deadLetterTargetArn\":\"arn:aws:sqs:eu-west-1:000000000000:work-queue.dlq\",\"maxReceiveCount\":\"3\"}"}'
$ aws --profile localstack --endpoint-url http://localhost:4566 sqs send-message \
--queue-url http://localhost:4566/000000000000/work-queue \
--message-body '{"key":"val"}'
Trying to consume messages 3 times.
$ aws --profile localstack --endpoint-url http://localhost:4566 sqs receive-message \
--queue-url http://localhost:4566/000000000000/work-queue \
--attribute-names All --message-attribute-names All --max-number-of-messages 10
$ aws --profile localstack --endpoint-url http://localhost:4566 sqs receive-message \
--queue-url http://localhost:4566/000000000000/work-queue \
--attribute-names All --message-attribute-names All --max-number-of-messages 10
$ aws --profile localstack --endpoint-url http://localhost:4566 sqs receive-message \
--queue-url http://localhost:4566/000000000000/work-queue \
--attribute-names All --message-attribute-names All --max-number-of-messages 10
Message should now be in the DLQ.
$ aws --profile localstack --endpoint-url http://localhost:4566 sqs receive-message \
--queue-url http://localhost:4566/000000000000/work-queue.dlq \
--attribute-names All --message-attribute-names All --max-number-of-messages 10