diff --git a/web/src/main/java/com/zhehekeji/web/config/ConfigProperties.java b/web/src/main/java/com/zhehekeji/web/config/ConfigProperties.java index 2c919dd..f667d62 100644 --- a/web/src/main/java/com/zhehekeji/web/config/ConfigProperties.java +++ b/web/src/main/java/com/zhehekeji/web/config/ConfigProperties.java @@ -82,6 +82,8 @@ public class ConfigProperties { public static class KSEC{ private String ip; private Integer port; + private Integer reconnectNum = 10; + private Integer reconnectInterval = 10; } @Data diff --git a/web/src/main/java/com/zhehekeji/web/service/ksec/KsecNettyClient.java b/web/src/main/java/com/zhehekeji/web/service/ksec/KsecNettyClient.java index 89a687f..703482f 100644 --- a/web/src/main/java/com/zhehekeji/web/service/ksec/KsecNettyClient.java +++ b/web/src/main/java/com/zhehekeji/web/service/ksec/KsecNettyClient.java @@ -25,10 +25,6 @@ public class KsecNettyClient { @Resource private ConfigProperties configProperties; - /** - * 重连最大次数 - */ - private static int RECONNECT_NUM = 10; private static Channel channel; @@ -68,13 +64,22 @@ public class KsecNettyClient { } catch (InterruptedException e) { e.printStackTrace(); } - while (num < RECONNECT_NUM && !isConnected) { + + /** + * 重连最大次数 + */ + while ((ksec.getReconnectNum() == -1 || num < ksec.getReconnectNum() ) && !isConnected) { try { createClient(ksec); } catch (Exception e) { //没连上 继续 log.error("reconnect error num:{}", num); num++; + try { + Thread.sleep(configProperties.getKsec().getReconnectNum()*1000); + } catch (InterruptedException ex) { + throw new RuntimeException(ex); + } continue; } isConnected = true; diff --git a/web/src/main/resources/application-test.yml b/web/src/main/resources/application-test.yml index 90415ee..47eb7e8 100644 --- a/web/src/main/resources/application-test.yml +++ b/web/src/main/resources/application-test.yml @@ -7,7 +7,7 @@ spring: maxWait: 60000 minEvictableIdleTimeMillis: 300000 minIdle: 15 - password: Leaper@123 + password: root poolPreparedStatements: true testOnBorrow: true testOnReturn: false @@ -48,6 +48,10 @@ serverMode: 1 ksec: ip: 127.0.0.1 port: 3000 + #重连次数 默认10次 + reconnectNum: 5 + #重连间隔 默认10s + reconnectInterval: 10 # ------------ 实时视频流 全部页面的格式 行列数量 videoStyleConfig: videoStyleRow: 2