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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package com.xzx.log.service;
 
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import com.rabbitmq.client.Channel;
import com.xzx.log.constants.Constants;
import com.xzx.log.constants.MqConstants;
import com.xzx.log.constants.QueueEnum;
import com.xzx.log.entity.IntefaceAdminLog;
import com.xzx.log.mapper.IntefaceAdminLogMapper;
import com.xzx.log.util.ExceptionUtils;
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.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import java.io.IOException;
import java.util.Date;
import java.util.List;
 
@Service
@Slf4j
public class IntefaceAdminLogService {
 
    @Autowired
    private IntefaceAdminLogMapper intefaceAdminLogMapper;
 
    @Autowired
    private MailService mailService;
 
    /**
     * 监听队列
     * @param message
     * @param channel
     * @throws IOException
     */
    @RabbitListener(queues = {MqConstants.INTEFACE_ADMIN_LOG_QUEUE})
    public void addQueue(Message message, Channel channel) throws IOException {
        log.debug("监听到接口消息队列");
        long deliveryTag =MqUtil.getTag(message);
        IntefaceAdminLog bean = MqUtil.getBean(message, IntefaceAdminLog.class);
        boolean success=true;
        try {
            intefaceAdminLogMapper.save(bean);
            mailService.sendEmail(CollUtil.newArrayList(bean));
        }catch (Exception e) {
            success=false;
        }
        if(success) {
            channel.basicAck(deliveryTag, false);
        }else {
            log.debug("丢弃接口消息");
            channel.basicNack(deliveryTag, false, false);
        }
    }
 
 
 
 
 
 
}