How to consume one message?

前端 未结 3 839
有刺的猬
有刺的猬 2021-01-13 05:56

With example in rabbitmq, consumer get all messages from queue at one time. How to consume one message and exit?

QueueingConsumer consumer = new QueueingCons         


        
3条回答
  •  南笙
    南笙 (楼主)
    2021-01-13 06:14

    const consumeFromQueue = async (queueName) => {
        try {
    
            let data = await channel.get(queueName)// get one msg at a time
            if (data) {
    
                data.content ? eval("(" + data.content.toString() + ")()") : ""
                channel.ack(data)
            } else {
                //console.log("Empty Queue")
            }
        }
        catch (error) {
            //console.log("Error while consuming from rabbitmq queue", error)
            return Promise.reject(error)
        }
    }
    

提交回复
热议问题