|
|
@ -5,6 +5,7 @@ import com.topsail.scheduletask.mapper.InformLogDao; |
|
|
import com.topsail.scheduletask.mapper.TopsailTransmitLogDao; |
|
|
import com.topsail.scheduletask.mapper.TopsailTransmitLogDao; |
|
|
import com.topsail.scheduletask.pojo.DeviceOnlineInfo; |
|
|
import com.topsail.scheduletask.pojo.DeviceOnlineInfo; |
|
|
import com.topsail.scheduletask.pojo.FocusDeviceOnline; |
|
|
import com.topsail.scheduletask.pojo.FocusDeviceOnline; |
|
|
|
|
|
import com.topsail.scheduletask.pojo.FocusMqCount; |
|
|
import com.topsail.scheduletask.service.AmqpService; |
|
|
import com.topsail.scheduletask.service.AmqpService; |
|
|
import com.topsail.scheduletask.util.MaiSenderlUtil; |
|
|
import com.topsail.scheduletask.util.MaiSenderlUtil; |
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
@ -42,25 +43,62 @@ public class CheckRabbitMqScheduleTask { |
|
|
//或直接指定时间间隔,例如:5秒 |
|
|
//或直接指定时间间隔,例如:5秒 |
|
|
// @Scheduled(fixedRate=5000) |
|
|
// @Scheduled(fixedRate=5000) |
|
|
private void checkRabbitMqCount() { |
|
|
private void checkRabbitMqCount() { |
|
|
//查询rabbitmq的队列名称 |
|
|
|
|
|
List<String> allQueueNames = amqpService.getAllQueueNames(); |
|
|
|
|
|
Map<String, Long> queueMessageCountMap = new HashMap<>(); |
|
|
|
|
|
for (String queueName : allQueueNames) { |
|
|
|
|
|
//跳过忽略的队列 |
|
|
|
|
|
if (queueName.equals(ignoreQueue)) { |
|
|
|
|
|
continue; |
|
|
|
|
|
} |
|
|
|
|
|
//获取队列中待消费的消息数量 |
|
|
|
|
|
long count = amqpService.getQueueMessageCount(queueName); |
|
|
|
|
|
if (count > 2000) { |
|
|
|
|
|
System.err.println("队列名称:" + queueName + ",待消费消息数量:" + count); |
|
|
|
|
|
queueMessageCountMap.put(queueName, count); |
|
|
|
|
|
|
|
|
try { |
|
|
|
|
|
//查询忽略的队列名称 |
|
|
|
|
|
List<FocusMqCount> list = topsailTransmitLogDao.getIgnoreQueue(1); |
|
|
|
|
|
if (list != null && list.size() > 0) { |
|
|
|
|
|
for (FocusMqCount focusMqCount : list) { |
|
|
|
|
|
StringBuilder ignoreQueueBuilder = new StringBuilder(); |
|
|
|
|
|
ignoreQueueBuilder.append(focusMqCount.getExcludeName()); |
|
|
|
|
|
//查询rabbitmq的队列名称 |
|
|
|
|
|
List<String> allQueueNames = amqpService.getAllQueueNames(); |
|
|
|
|
|
Map<String, Long> queueMessageCountMap = new HashMap<>(); |
|
|
|
|
|
for (String queueName : allQueueNames) { |
|
|
|
|
|
//跳过忽略的队列 |
|
|
|
|
|
if (ignoreQueueBuilder.toString().contains(queueName)) { |
|
|
|
|
|
continue; |
|
|
|
|
|
} |
|
|
|
|
|
//获取队列中待消费的消息数量 |
|
|
|
|
|
long count = amqpService.getQueueMessageCount(queueName); |
|
|
|
|
|
if (count > 2000) { |
|
|
|
|
|
System.err.println("队列名称:" + queueName + ",待消费消息数量:" + count); |
|
|
|
|
|
queueMessageCountMap.put(queueName, count); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
if (ignoreQueueBuilder.length() > 0) { |
|
|
|
|
|
ignoreQueueBuilder.delete(0, ignoreQueueBuilder.length()); |
|
|
|
|
|
} |
|
|
|
|
|
if (queueMessageCountMap.size() > 0) { |
|
|
|
|
|
//将queueMessageCountMap转成json字符串 |
|
|
|
|
|
String json = JSON.toJSONString(queueMessageCountMap); |
|
|
|
|
|
String subject = "MQ中设备数据流转异常"; |
|
|
|
|
|
String today = new SimpleDateFormat("yyyy-MM-dd HH:00:00").format(new Date()); |
|
|
|
|
|
Integer logCount = informLogDao.getNewInformLogCount(subject, today); |
|
|
|
|
|
if (focusMqCount.getSendMails() != null && logCount != null && logCount < 1) { |
|
|
|
|
|
if (focusMqCount.getSendMails().contains(",")) { |
|
|
|
|
|
String[] mails = focusMqCount.getSendMails().split(","); |
|
|
|
|
|
for (String mail : mails) { |
|
|
|
|
|
//验证邮箱格式 |
|
|
|
|
|
if (!maiSenderlUtil.isEmail(mail)) { |
|
|
|
|
|
continue; |
|
|
|
|
|
} |
|
|
|
|
|
//3.发送邮件 |
|
|
|
|
|
String content = subject + ",待消费消息数量:" + json; |
|
|
|
|
|
maiSenderlUtil.sendMail(mail, subject, content, true, null, subject); |
|
|
|
|
|
} |
|
|
|
|
|
} else { |
|
|
|
|
|
String content = subject + ",待消费消息数量:" + json; |
|
|
|
|
|
maiSenderlUtil.sendMail(maiSenderlUtil.isEmail(focusMqCount.getSendMails()) ? focusMqCount.getSendMails() : "1129801211@qq.com", subject, content, true, null, subject); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
// amqpService.SendMessage("mailNotice", json); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
if (queueMessageCountMap.size() > 0) { |
|
|
|
|
|
//将queueMessageCountMap转成json字符串 |
|
|
|
|
|
String json = JSON.toJSONString(queueMessageCountMap); |
|
|
|
|
|
amqpService.SendMessage("mailNotice", json); |
|
|
|
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
e.printStackTrace(); |
|
|
|
|
|
System.out.println("发送邮件失败"); |
|
|
|
|
|
System.out.println(e.getMessage()); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -106,11 +144,11 @@ public class CheckRabbitMqScheduleTask { |
|
|
continue; |
|
|
continue; |
|
|
} |
|
|
} |
|
|
//3.发送邮件 |
|
|
//3.发送邮件 |
|
|
String content = "客户:" + focusDeviceOnline.getUserName() + ",设备离线数量:" + offlineDevices.size() + "个,"+"报警设备和预离线时间信息:"+json+"。请进入系统查看原因"; |
|
|
|
|
|
|
|
|
String content = "客户:" + focusDeviceOnline.getUserName() + ",设备离线数量:" + offlineDevices.size() + "个," + "报警设备和预离线时间信息:" + json + "。请进入系统查看原因"; |
|
|
maiSenderlUtil.sendMail(mail, subject, content, true, null, subject); |
|
|
maiSenderlUtil.sendMail(mail, subject, content, true, null, subject); |
|
|
} |
|
|
} |
|
|
} else { |
|
|
} else { |
|
|
String content = "客户:" + focusDeviceOnline.getUserName() + ",设备离线数量:" + offlineDevices.size() + "个,"+"报警设备和预离线时间信息:"+json+"。请进入系统查看原因"; |
|
|
|
|
|
|
|
|
String content = "客户:" + focusDeviceOnline.getUserName() + ",设备离线数量:" + offlineDevices.size() + "个," + "报警设备和预离线时间信息:" + json + "。请进入系统查看原因"; |
|
|
maiSenderlUtil.sendMail(maiSenderlUtil.isEmail(focusDeviceOnline.getSendMails()) ? focusDeviceOnline.getSendMails() : "1129801211@qq.com", subject, content, true, null, subject); |
|
|
maiSenderlUtil.sendMail(maiSenderlUtil.isEmail(focusDeviceOnline.getSendMails()) ? focusDeviceOnline.getSendMails() : "1129801211@qq.com", subject, content, true, null, subject); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|