admin
2022-08-25 264b5dea5b74c4b5ba54a90caba7e709858a037e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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);
        }
    }
}