SQS ReceiveMessage 成功但收到空消息
SQS ReceiveMessage succeeds but gets a null message
我在 lambda 中有以下代码来接收 SQS 消息:
当我将消息注入 SQS 时,lambda 触发,但显示 data.Messages 为空。
function receiveMessages(callback)
{
var params = {
QueueUrl: TASK_QUEUE_URL,
MaxNumberOfMessages: 2,
WaitTimeSeconds: 1,
AttributeNames: ["All"]
};
SQS.receiveMessage(params, function(err, data)
{
if (err)
{
console.error(err, err.stack);
callback(err);
}
else if (data.Messages == null)
{
console.log("null message", data);
callback(null,null);
}
else
{
callback(null, data.Messages);
}
});
}
我可能做错了什么并不明显。我尝试了 fifo 和非 fifo 队列
当 using an SQS Queue as a Lambda event source 时,Lambda 服务的一个组件实际上轮询队列并将消息负载传递给函数调用,在数组 event.Records
中,该数组将包含一条或多条来自队列。消息在队列中暂时不可见(它们是 "in flight")。
您无需在此应用程序中直接与 SQS 交互。
您处理消息并成功退出 Lambda 函数,Lambda 轮询程序会自动从队列中删除刚刚提供给您的所有消息。
如果抛出异常,您刚刚传递的所有消息都将重新设置为在队列中可见。
我在 lambda 中有以下代码来接收 SQS 消息: 当我将消息注入 SQS 时,lambda 触发,但显示 data.Messages 为空。
function receiveMessages(callback)
{
var params = {
QueueUrl: TASK_QUEUE_URL,
MaxNumberOfMessages: 2,
WaitTimeSeconds: 1,
AttributeNames: ["All"]
};
SQS.receiveMessage(params, function(err, data)
{
if (err)
{
console.error(err, err.stack);
callback(err);
}
else if (data.Messages == null)
{
console.log("null message", data);
callback(null,null);
}
else
{
callback(null, data.Messages);
}
});
}
我可能做错了什么并不明显。我尝试了 fifo 和非 fifo 队列
当 using an SQS Queue as a Lambda event source 时,Lambda 服务的一个组件实际上轮询队列并将消息负载传递给函数调用,在数组 event.Records
中,该数组将包含一条或多条来自队列。消息在队列中暂时不可见(它们是 "in flight")。
您无需在此应用程序中直接与 SQS 交互。
您处理消息并成功退出 Lambda 函数,Lambda 轮询程序会自动从队列中删除刚刚提供给您的所有消息。
如果抛出异常,您刚刚传递的所有消息都将重新设置为在队列中可见。