19/01/2022 - AWS
Bu örnekte, AWS SNS'e giden iletiler daha sonra AWS SQS'e iletilecek ve oradan işlenecekler. 3 denemeden sonra mesajları AWS SQS kaynak kuyruğundan DLQ'ya taşıyacağız. İletiler herhangi bir nedenle işlenmezse yeniden denemeler gerçekleşir. Mesaj, her deneme arasında her 30 saniyede bir görünür olacaktır.
// Create SQS queue
$ aws --profile localstack --endpoint-url http://localhost:4566 sqs create-queue \
--queue-name test-queue.dlq
// Create SQS DLQ queue
$ aws --profile localstack --endpoint-url http://localhost:4566 sqs create-queue \
--queue-name test-queue \
--attributes '{"RedrivePolicy":"{\"deadLetterTargetArn\":\"arn:aws:sqs:eu-west-1:000000000000:test-queue.dlq\",\"maxReceiveCount\":\"3\"}"}'
// Create SNS topic
$ aws --profile localstack --endpoint-url http://localhost:4566 sns create-topic \
--name test-topic
// Subscribe SQS queue to SNS topic
$ aws --profile localstack --endpoint-url http://localhost:4566 sns subscribe \
--protocol sqs \
--topic-arn arn:aws:sns:eu-west-1:000000000000:test-topic \
--notification-endpoint arn:aws:sqs:eu-west-1:000000000000:test-queue
$ aws --profile localstack --endpoint-url http://localhost:4566 sns publish \
--topic-arn arn:aws:sns:eu-west-1:000000000000:test-topic \
--message 'Hello'
Mesajları 3 kez tüketmeye çalışıyorum.
$ aws --profile localstack --endpoint-url http://localhost:4566 sqs receive-message \
--queue-url http://localhost:4566/000000000000/test-queue \
--attribute-names All --message-attribute-names All
$ aws --profile localstack --endpoint-url http://localhost:4566 sqs receive-message \
--queue-url http://localhost:4566/000000000000/test-queue \
--attribute-names All --message-attribute-names All
$ aws --profile localstack --endpoint-url http://localhost:4566 sqs receive-message \
--queue-url http://localhost:4566/000000000000/test-queue \
--attribute-names All --message-attribute-names All
Mesaj şimdi DLQ'da olmalıdır.
$ aws --profile localstack --endpoint-url http://localhost:4566 sqs receive-message \
--queue-url http://localhost:4566/000000000000/test-queue.dlq \
--attribute-names All --message-attribute-names All