Bläddra i källkod

增加处理报警缓冲iswriteable=false的定时任务

lgy 4 år sedan
förälder
incheckning
43ced1baf1
1 ändrade filer med 16 tillägg och 2 borttagningar
  1. 16 2
      src/main/java/com/persagy/job/SpringSchedule.java

+ 16 - 2
src/main/java/com/persagy/job/SpringSchedule.java

@@ -2,7 +2,9 @@ package com.persagy.job;
 
 import com.persagy.client.GroupNettyClient;
 import com.persagy.entity.NettyMessage;
+import io.netty.channel.ChannelHandlerContext;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.scheduling.annotation.EnableScheduling;
 import org.springframework.scheduling.annotation.Scheduled;
@@ -38,9 +40,21 @@ public class SpringSchedule {
             return;
         }
         log.info("NettyClient State:isActive[{}],isOpen[{}],isRegistered[{}],isWritable[{}]",GroupNettyClient.channelGroup.isActive(),GroupNettyClient.channelGroup.isOpen(),GroupNettyClient.channelGroup.isRegistered(),GroupNettyClient.channelGroup.isWritable());
-
+        sengAlarmMessage();
     }
 
-
+    private void sengAlarmMessage() {
+        try {
+            log.info("--sengAlarmMessage--");
+            String msg = NettyMessageQueue.getNettyMessageQueue().consume();
+            while (StringUtils.isNotBlank(msg)){
+                log.info("剩余报警消息令总数:{}",NettyMessageQueue.getNettyMessageQueue().size());
+                groupNettyClient.sendMessage(msg);
+                msg = NettyMessageQueue.getNettyMessageQueue().consume();
+            }
+        } catch (Exception e) {
+            log.error("发送报警消息失败",e);
+        }
+    }
 
 }