diff --git a/api-admin/src/main/java/com/glxp/sale/admin/socket/client/WebSocketComponent.java b/api-admin/src/main/java/com/glxp/sale/admin/socket/client/WebSocketComponent.java index 8068efe..53fc5cb 100644 --- a/api-admin/src/main/java/com/glxp/sale/admin/socket/client/WebSocketComponent.java +++ b/api-admin/src/main/java/com/glxp/sale/admin/socket/client/WebSocketComponent.java @@ -1,5 +1,6 @@ package com.glxp.sale.admin.socket.client; +import cn.hutool.core.thread.ThreadUtil; import com.glxp.sale.admin.constant.SocketMsgType; import com.glxp.sale.admin.service.param.SystemParamConfigService; import com.glxp.sale.admin.thread.HeartTaskService; @@ -29,34 +30,40 @@ public class WebSocketComponent implements CommandLineRunner { @Override public void run(String... args) throws Exception { - String ip = systemParamConfigService.selectValueByParamKey("upper_server_ip"); - ip = ip.replace("http://", ""); - try { - SpsWebSocketClient client = new SpsWebSocketClient("ws://" + ip + "/spms/sync/1/" + socketToken); - client.setSocketMsgService(socketMsgService); - initConnect(client); - //等待WebSocket服务端响应 - String message = null; - while (true) { - while ((message = client.getExcptMessage()) == null) { - log.info("已连接,等待接收数据--------"); - Thread.sleep(1000); - if (client.isClosed()) { + + ThreadUtil.execAsync(() -> { + String ip = systemParamConfigService.selectValueByParamKey("upper_server_ip"); + ip = ip.replace("http://", ""); + try { + SpsWebSocketClient client = new SpsWebSocketClient("ws://" + ip + "/spms/sync/1/" + socketToken); + client.setSocketMsgService(socketMsgService); initConnect(client); + //等待WebSocket服务端响应 + String message = null; + while (true) { + while ((message = client.getExcptMessage()) == null) { + log.info("已连接,等待接收数据--------"); + Thread.sleep(1000); + if (client.isClosed()) { + initConnect(client); + } + } + if (message.contains(SocketMsgType.DL_ALL_DATA)) { + heartTaskService.dlAllData(); + } + //打印服务端返回的数据 + log.info("成功获取数据:" + message); + } + + } catch (URISyntaxException e) { + e.printStackTrace(); + } catch (InterruptedException e) { + e.printStackTrace(); } } - if (message.contains(SocketMsgType.DL_ALL_DATA)) { - heartTaskService.dlAllData(); - } - //打印服务端返回的数据 - log.info("成功获取数据:" + message); - } + ); + - } catch (URISyntaxException e) { - e.printStackTrace(); - } catch (InterruptedException e) { - e.printStackTrace(); - } } public void initConnect(SpsWebSocketClient client) { diff --git a/api-admin/src/main/java/com/glxp/sale/admin/socket/server/SpsSyncWebSocket.java b/api-admin/src/main/java/com/glxp/sale/admin/socket/server/SpsSyncWebSocket.java index 9eaca43..9bb69f7 100644 --- a/api-admin/src/main/java/com/glxp/sale/admin/socket/server/SpsSyncWebSocket.java +++ b/api-admin/src/main/java/com/glxp/sale/admin/socket/server/SpsSyncWebSocket.java @@ -100,7 +100,7 @@ public class SpsSyncWebSocket { // value.session.getBasicRemote().sendText(s); // } // 推送结束符 - value.session.getBasicRemote().sendText("#end#"); +// value.session.getBasicRemote().sendText("#end#"); } } catch (IOException e) { e.printStackTrace(); @@ -128,7 +128,7 @@ public class SpsSyncWebSocket { // value.session.getBasicRemote().sendText(s); // } // 推送结束符 - value.session.getBasicRemote().sendText("#end#"); +// value.session.getBasicRemote().sendText("#end#"); } } catch (IOException e) { e.printStackTrace();