package com.yeshi.buwan.util.mq.consumer; import com.rabbitmq.client.Channel; import org.springframework.amqp.core.Message; import org.springframework.amqp.rabbit.listener.api.ChannelAwareMessageListener; /** * @author hxh * @title: QueueHelloWorldListener * @description: TODO * @date 2022/8/1 11:37 */ public class QueueHelloWorldListener implements ChannelAwareMessageListener { @Override public void onMessage(Message message, Channel channel) throws Exception { long deliveryTag = message.getMessageProperties().getDeliveryTag(); try{ channel.basicAck(deliveryTag, true); }catch(Exception e){ // 拒绝签收 // 第三个参数:requeue:重回队列。如果设置为true,则消息重新回到queue,broker会重新发送该消息给消费端 // 如果是false, 则消息被丢弃 channel.basicNack(deliveryTag, true, true); } } }