我amqplib
在 nodejs 应用程序中使用。前端有一些繁重的处理会导致接收rabbitmq消息时出现一些延迟。当使用 监控我的队列时rabbitmqctl list_queues
,等待处理的消息数量永远不会停止攀升。
有没有办法设置我的频道以便在队列有给定数量的消息等待时丢弃消息?
以下是我设置频道的方式:
amqp.connect('amqp://localhost')
.then(conn => {
return conn.createChannel();
})
.then(channel => {
channel.assertQueue(q, {durable: false, autoDelete: true});
channel.prefetch(1);
channel.bindQueue(q.queue, topic, 'myroutingkey');
return channel.consume(q, (msg) => {
mycallback(channel, msg);
});
})
.then(() => {})
.catch(err => {});