How to get messages receive count in Amazon SQS using boto library in Python?

前端 未结 5 1929
不知归路
不知归路 2021-02-09 00:29

I am using boto library in Python to get Amazon SQS messages. In exceptional cases I don\'t delete messages from queue in order to give a couple of more changes to recover tempo

5条回答
  •  终归单人心
    2021-02-09 00:56

    Get ApproximateReceiveCount attribute from message you read. move it to another queue(than you can manage error messages) or just delete it.

    foreach (var message in response.Messages){
           try{
               var notifyMessage = JsonConvert.DeserializeObject(message.Body);
                        Global.Sqs.DeleteMessageFromQ(message.ReceiptHandle);
               }
           catch (Exception ex){
               var  receiveMessageCount = int.Parse(message.Attributes["ApproximateReceiveCount"]);
               if (receiveMessageCount >3 ) 
                  Global.Sqs.DeleteMessageFromQ(message.ReceiptHandle);
                }
            }
    

提交回复
热议问题