Browse Source

修改批量实时数据写入传输批次大小

wangb@gyee-china.com 1 year ago
parent
commit
cfca17800d

+ 25 - 10
realtime/generationXK-service/src/main/java/com/gyee/generation/util/realtimesource/EdosUtil.java

@@ -1610,18 +1610,33 @@ public class EdosUtil implements IEdosUtil {
     public void sendMultiPoint(List<PointData> pointls) throws Exception {
 
         String url = baseURL + "/latest/batch";
+
         List<JSONObject> writeList = new ArrayList<>();
 
-        for (PointData entity : pointls) {
-            writeList.add(convertPointData(entity));
-        }
-        try {
-            String result = restTemplate.postForObject(url, writeList, String.class);
-        } catch (HttpClientErrorException exception) {
-            if (exception.getStatusCode() == HttpStatus.NOT_FOUND) {
-                System.out.println("404请求错误");
-            } else {
-                throw exception;
+        int batchSize = 500; // 设置每次传输的批次大小
+
+        int totalSize = pointls.size();
+        int batchCount = totalSize % batchSize == 0 ? totalSize / batchSize : totalSize / batchSize + 1;
+
+        for (int i = 0; i < batchCount; i++) {
+            int startIndex = i * batchSize;
+            int endIndex = Math.min((i + 1) * batchSize, totalSize);
+            List<PointData> batch = pointls.subList(startIndex, endIndex);
+
+            List<JSONObject> batchWriteList = new ArrayList<>();
+            for (PointData entity : batch) {
+                batchWriteList.add(convertPointData(entity));
+            }
+
+            try {
+                String result = restTemplate.postForObject(url, batchWriteList, String.class);
+                // 处理返回的结果
+            } catch (HttpClientErrorException exception) {
+                if (exception.getStatusCode() == HttpStatus.NOT_FOUND) {
+                    throw new Exception("404请求错误");
+                } else {
+                    throw exception;
+                }
             }
         }
     }