Browse Source

no message

wwd 3 years ago
parent
commit
48e559b982

+ 14 - 7
src/main/java/com/persagy/ztkedgeclouddatasecurity/netty/cloud/NettyClient.java

@@ -1,5 +1,6 @@
 package com.persagy.ztkedgeclouddatasecurity.netty.cloud;
 
+import cn.hutool.core.thread.ThreadUtil;
 import com.alibaba.fastjson.JSONObject;
 import com.alibaba.fastjson.TypeReference;
 import com.persagy.ztkedgeclouddatasecurity.entity.NettyMessage;
@@ -13,7 +14,6 @@ import io.netty.channel.socket.nio.NioSocketChannel;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
-import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
 import org.springframework.stereotype.Component;
 
 import javax.annotation.PostConstruct;
@@ -34,16 +34,22 @@ public class NettyClient {
     private String Connectinfo;
 
     @PostConstruct
-    public void connect() {
+    public void startNetty(){
+        String[] connectInfoArr=Connectinfo.split(",");
+        for (int i=0;i<connectInfoArr.length;i++){
+            int finalI = i;
+            ThreadUtil.execAsync(()->{connect(finalI,connectInfoArr);}, true);
+        }
+
+    }
+
+
+    public Runnable connect(int i, String[] connectInfoArr) {
         EventLoopGroup workerGroup = new NioEventLoopGroup();
         bootstrap.group(workerGroup);
         bootstrap.channel(NioSocketChannel.class);
         bootstrap.option(ChannelOption.AUTO_READ, true);
 
-
-        String[] connectInfoArr=Connectinfo.split(",");
-        for (int i=0;i<connectInfoArr.length;i++){
-
             String ip= connectInfoArr[i].split(":")[2];
             int port = Integer.valueOf(connectInfoArr[i].split(":")[3]);
             String projectId = connectInfoArr[i].split(":")[3]+"_"+connectInfoArr[i].split(":")[1];
@@ -57,7 +63,8 @@ public class NettyClient {
         } finally {
             //workerGroup.shutdownGracefully();
         }
-        }
+
+        return null;
     }