managing AWS SQS and DLQ

為{幸葍}努か 提交于 2019-12-12 07:00:53

问题


Scenario :

create a lambda and it will be triggered whenever a message comes to SQS(let's assume SQS-A). The lambda (written in python)is responsible for sending the incoming payload to the another endpoint.

The problem is, whenever the target endpoint or server is down, I was trying to place it into the another SQS (let's assume SQS-B), if other exceptions comes than placing it into Deal Letter Queue.

Here I want to two things.

  1. If ConnectionError (it is the python exception says which says endpoint is down) comes I want to stop the the SQS-A(there is no point to run the lambda as the target server is down).

(or)

  1. As whenever I get this error I am sending it to the SQS-B, I want the SQS-B to be triggered for when the first request comes and it should check if still there is a connection error, it has to trigger after 10 minutes, and again check, if exception persists trigger after 30 minutes, like this I want to increment the time up to 4 hours and after that check/trigger the lambda every 4 hours. If there is no exception then it should read all the messages in the SQS-B.

Help me how to achieve any one of the approach or recommend any other better approach


回答1:


You are creating a complex architecture due to a simple problem (the target not being available). Try not to over-complicate things.

I would recommend:

  • Have the originating system send the message to an Amazon SNS topic
  • The topic triggers a Lambda function
    • If it successfully processes the message, no further action required
    • If the remote endpoint is not available, put the message into an Amazon SQS queue for later processing
  • Use Amazon CloudWatch Events to trigger a Lambda function every n minutes that grabs any messages in the queue and tries to send them again. If the remote endpoint is still down, it exits and the process will be attempted again n minutes later.
    • Probably worth also sending an email to an Admin if a message gets older than a few hours.

If you must send the original message to an SQS queue, then you could do as you described... send to Queue-A first, which triggers a Lambda function. If the endpoint is down, Lambda sends the message to Queue-B for later processing. However, only process from Queue-B every n minutes (rather than trying to make each individual message have its own delay timer).



来源:https://stackoverflow.com/questions/51441240/managing-aws-sqs-and-dlq

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!