From 1c3ea016e69d00a37a3e65233807b64df209a24d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?LAPTOP-S9HJSOEB=5C=E6=98=8A=E5=A4=A9?= Date: Thu, 30 Mar 2023 13:21:31 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E9=85=8D=E7=BD=AE=E6=96=87?= =?UTF-8?q?=E4=BB=B6ksec=E5=8F=82=E6=95=B0=20=20reconnectNum#=E9=87=8D?= =?UTF-8?q?=E8=BF=9E=E6=AC=A1=E6=95=B0=20=E9=BB=98=E8=AE=A410=E6=AC=A1-1?= =?UTF-8?q?=E6=B0=B8=E8=BF=9C=E9=87=8D=E8=BF=9E=EF=BC=8CreconnectInterval#?= =?UTF-8?q?=E9=87=8D=E8=BF=9E=E9=97=B4=E9=9A=94=20=E9=BB=98=E8=AE=A410s?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../zhehekeji/web/config/ConfigProperties.java | 2 ++ .../web/service/ksec/KsecNettyClient.java | 15 ++++++++++----- web/src/main/resources/application-test.yml | 6 +++++- 3 files changed, 17 insertions(+), 6 deletions(-) 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