检查AWS sqs中的传入消息 [英] Check for an incoming message in aws sqs
问题描述
我的功能如何连续检查传入的消息?收到消息后,以下功能退出.考虑到已为队列启用了长时间轮询,如何连续检查新消息?
How does my function continuously check for an incoming message? The following function exits, after receiving a message. Considering, long polling has been enabled for the queue how do I continuously check for a new message?
function checkMessage(){
var params = {
QueueUrl : Constant.QUEUE_URL,
VisibilityTimeout: 0,
WaitTimeSeconds: 0
}
sqs.receiveMessage(params,(err,data) => {
if(data){
console.log("%o",data);
}
});
}
推荐答案
您的函数将需要不断轮询Amazon SQS.
Your function would need to continually poll Amazon SQS.
长时间轮询会将响应最多延迟20秒.如果在此期间有消息可用,它将立即返回.如果20秒后没有任何消息,它将返回而不提供消息.
Long Polling will delay a response by up to 20 seconds if there are no messages available. If a message becomes available during that period, it will be immediately returned. If there is no message after 20 seconds, it returns without providing a message.
因此,您的函数将需要再次轮询SQS(可能同时进行其他操作).
Therefore, your function would need to poll SQS again (perhaps doing something else in the meantime).
这篇关于检查AWS sqs中的传入消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!