Browse Source

设备与报警条件关联关系变化发送消息到mq,限制一次发送的条数

lixing 3 years ago
parent
commit
35de36b343
1 changed files with 12 additions and 5 deletions
  1. 12 5
      src/main/java/com/persagy/apm/alarmservice/common/jms/JmsSender.java

+ 12 - 5
src/main/java/com/persagy/apm/alarmservice/common/jms/JmsSender.java

@@ -2,6 +2,7 @@ package com.persagy.apm.alarmservice.common.jms;
 
 import cn.hutool.core.lang.generator.UUIDGenerator;
 import com.alibaba.fastjson.JSONObject;
+import com.google.common.collect.Lists;
 import com.persagy.apm.alarmservice.common.configuration.rabbitmq.JacksonMapper;
 import com.persagy.apm.alarmservice.common.enums.JmsTypeEnum;
 import com.persagy.apm.alarmservice.common.model.DmpMessage;
@@ -171,12 +172,18 @@ public class JmsSender {
         if (CollectionUtils.isEmpty(relList)) {
             return;
         }
-        UUIDGenerator uuidGenerator = new UUIDGenerator();
-        dmpMessage.setMid(uuidGenerator.next());
-        dmpMessage.setStr1(JSONObject.toJSONString(relList));
-        dmpMessage.setType(JmsTypeEnum.NEW_OBJ_CONDITION_REL.getType());
 
-        sendObjConditionRelMsg(dmpMessage);
+        // 因为阿里云mq单个消息限制大小为64k。将关联关系消息分批放入mq,每次发送200条数据
+        int onceSendCount = 200;
+        List<List<ObjConditionRel>> partition = Lists.partition(relList, onceSendCount);
+
+        for (List<ObjConditionRel> objConditionRels : partition) {
+            UUIDGenerator uuidGenerator = new UUIDGenerator();
+            dmpMessage.setMid(uuidGenerator.next());
+            dmpMessage.setStr1(JSONObject.toJSONString(objConditionRels));
+            dmpMessage.setType(JmsTypeEnum.NEW_OBJ_CONDITION_REL.getType());
+            sendObjConditionRelMsg(dmpMessage);
+        }
     }
 
     /**