I have send message api to my users.
When I send to message from my x numbers I need to wait 10-15 seconds for doesn't get ban from whatsapp.
I'm using 5 different senders and 5 consumers in rabbitmq. When message came from postgres_notify it's adding to queue and I'm checking sender number. If its numberx I'm sending message with post requests. But When I add 10 queue to rabbitmq, It's waiting x consumers complete. If number x,y,z and consumerx need to take x, consumery need to take y and ... How can I do that?
我已经向我的用户发送消息API。当我从我的x号码发送消息时,我需要等待10-15秒才能收到WhatsApp的禁令。我在Rabbitmq上使用了5个不同的发送者和5个消费者。当消息来自postgres_tify时,它正在添加到队列中,而我正在检查发件人编号。如果它的号码是x,我会用POST请求发送消息。但当我将10个队列添加到rabbitmq时,它正在等待x个消费者完成。如果数字x,y,z和Consumer x需要取x,消耗者需要取y和...我怎么能做到这一点?
async function connect() {
try {
const connection = await amqp.connect(opts);
connection.on("error", (error) => {
console.error("Connection error : ", error);
});
const channel = await connection.createChannel();
channel.on("error", (error) => {
console.error("Channel error : ", error);
});
const result = await channel.assertQueue(process.env.RABBITMQ_CHANNEL_CP);
console.log("Waiting for Whatsapp Message");
channel.prefetch(1);
channel.consume(process.env.RABBITMQ_CHANNEL_CP, message => {
let msg = JSON.parse(message.content.toString());
if (parseInt(msg.sender) == senderx){
setTimeout(() => {
ws.getWhatsappSender(msg.sender, (err, response) => {
if (response){
try{
dosomething()
channel.ack(message);
}
catch (e) {
channel.reject(message,true);
channel.ack(message);
}
}
});
}, Math.floor(Math.random() * (15 - 10 + 1)) + 10);
}
else{
channel.nack(message, false, true);
}
}, {noAck: false});
} catch (e) {
console.error(e);
console.log("Create SMS Queue Error", e);
}
}
I'm trying setTimeout function.
我正在尝试设置超时功能。
更多回答
优秀答案推荐
我是一名优秀的程序员,十分优秀!