消费者包装看起来好像我没有收到所有消息
我的应用程序中的日志 第一条消息: queueUrl:https://sqs.us-east-2.amazonaws.com/xxxxxxx/tasks messageId:aa1fdc71-a19c-4263-9bf0-xxxxxx <--------------- ## 1
第二条消息: queueUrl:https://sqs.us-east-2.amazonaws.com/xxxxxxx/tasks messageId:ca855b33-be5a-4f47-806f-xxxxxx
消费者
收到的邮件{ MessageId:“ aa1fdc71-a19c-4263-9bf0-xxxxxxx”,<--------------- ## 1 ReceiptHandle:“ xxxxxxxxxxxxxx”, MD5OfBody:“ xxxxxxxxxxxxx”, 正文:“ {“ test”:1}' }
消息已处理 消息为空
我不知道为什么message2没有消耗??
var AWS = require('aws-sdk');
const { Consumer } = require('sqs-consumer');
const task = require('../../jobs/task');
AWS.config.update({
accessKeyId: process.env.SQS_API_KEY,
secretAccessKey: process.env.SQS_API_SECRET_KEY,
region: process.env.SQS_REGION
});
const app = Consumer.create({
queueUrl: `https://sqs.${process.env.SQS_REGION}.amazonaws.com/${process.env.SQS_ACCOUNT_ID}/tasks`,
waitTimeSeconds: 20,
visibilityTimeout: 90,
handleMessage: async (message) => {
let obj = JSON.parse(message.Body)
//my logic here
await task.startFetching(obj.test)
return;
}
});
app.on('error', (err) => {
console.log('[SQS WORKER]',err.message)
});
app.on('processing_error', (err) => {
console.log('[SQS WORKER]',err.message)
});
app.on('timeout_error', (err) => {
console.error('[SQS WORKER]',err.message);
});
app.on('message_received',(message) => {
console.log('[SQS WORKER]','message received',message);
})
app.on('response_processed',()=> {
console.log('[SQS WORKER]','message processed')
})
app.on('stopped',()=> {
console.log('[SQS WORKER]','message stopped')
})
app.on('empty',() => {
console.log('[SQS WORKER]','message empty')
})
app.start();
console.log(`[TASK WORKER] is listening...`);
另一件事是,我该如何让消费者使用一条消息并等待我的逻辑直到完成,然后接收下一条消息
先谢谢您