From 4aeae0f31c8654bb8bce9937ec83845af89f0ffa Mon Sep 17 00:00:00 2001 From: kanade Date: Tue, 26 Jul 2022 17:50:49 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E9=A2=84=E6=B6=88=E8=B4=B9?= =?UTF-8?q?=E6=95=B0=E9=87=8F=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- rabbitmq.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/rabbitmq.go b/rabbitmq.go index 382aa90..a933f8f 100644 --- a/rabbitmq.go +++ b/rabbitmq.go @@ -46,13 +46,19 @@ func (r *rabbitmq) Publish(exchangeName, msg string, delay ...int64) error { // Consume @Title 消费队列 // @Param queueName string true "队列名称" // @Param autoAck bool true "是否自动确认" +// @Param prefetchCount int 0 "预消费数量" // @Param callback func(amqp.Delivery)) true "回调处理" -func (r *rabbitmq) Consume(queueName string, autoAck bool, callback func(amqp.Delivery)) error { +func (r *rabbitmq) Consume(queueName string, autoAck bool, prefetchCount int, callback func(amqp.Delivery)) error { ch, err := r.Conn.Channel() if err != nil { return err } defer ch.Close() + if prefetchCount > 0 { + if err := ch.Qos(prefetchCount, 0, false); err != nil { + return err + } + } //消费队列 msgs, err := ch.Consume( queueName, //队列名称