Helius
2021-06-21 5812839f3e23bb09e1a9b100b63273a646155709
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
27
28
29
30
31
32
33
34
35
package com.xzx.log.queue;
 
import cn.hutool.json.JSONUtil;
import com.rabbitmq.client.Channel;
import com.xzx.log.constants.MqConstants;
import com.xzx.log.util.MqUtil;
import com.xzx.log.util.RedisUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
 
import java.io.IOException;
 
 
/**
 * 死信队列
 */
@Component
@Slf4j
public class DeadConsumer {
 
    @Autowired
    private RedisUtil redisUtil;
 
    @RabbitListener(queues =MqConstants.DEAD_QUEUE)
    public void process(Message message,Channel channel) throws IOException {
        long deliveryTag = MqUtil.getTag(message);
        channel.basicAck(deliveryTag, false);
        // 获取消息Id
        redisUtil.rpush(MqConstants.ERR_QUEUE_REDIS,MqUtil.getMsg(message));
    }
 
}