【发布时间】:2019-05-17 08:02:24
【问题描述】:
我有从 SQS 队列读取消息的 lambda 触发器。在某些情况下,消息可能尚未准备好进行处理,因此我想将消息放回队列中等待 1 分钟,然后重试。目前,我正在创建此客户记录的另一个副本并将此新副本发布到队列中。我是否有理由/方式将原始记录保留在队列中,而不是创建新记录
def postToQueue(customer):
if 'attemptCount' in customer.keys():
attemptCount = int(customer["attemptCount"]) + 1
else:
attemptCount = 2
customer["attemptCount"] = attemptCount
# Get the service resource
sqs = boto3.resource('sqs')
# Get the queue
queue = sqs.get_queue_by_name(QueueName='testCustomerQueue')
response = queue.send_message(MessageBody=json.dumps(customer), DelaySeconds=60)
print('customer postback: ', customer)
print ('response from writing ot the queue is: ', response)
#main function
for record in event['Records']:
if 'body' in record.keys():
customer = json.loads(record['body'])
print("attempting to process customer", customer, " at: ", datetime.datetime.now())
if (not ifReadyToProcess(customer)):
postToQueue(customer)
else:
processCustomer(customer)
【问题讨论】:
标签: aws-lambda amazon-sqs