From c40fc0cc01b12f6fab6db90af395eb241e0e2aaf Mon Sep 17 00:00:00 2001
From: 13693261870 <252740454@qq.com>
Date: 星期四, 26 十月 2023 15:55:32 +0800
Subject: [PATCH] 解决WS消息推送报错

---
 src/main/java/com/moon/server/service/data/RasterAnalysisService.java |    3 ++-
 src/main/java/com/moon/server/service/all/WebSocketService.java       |   18 ++++--------------
 src/main/resources/application.yml                                    |    8 ++++----
 3 files changed, 10 insertions(+), 19 deletions(-)

diff --git a/src/main/java/com/moon/server/service/all/WebSocketService.java b/src/main/java/com/moon/server/service/all/WebSocketService.java
index 2d3d690..6066f89 100644
--- a/src/main/java/com/moon/server/service/all/WebSocketService.java
+++ b/src/main/java/com/moon/server/service/all/WebSocketService.java
@@ -68,9 +68,6 @@
 
     /**
      * 鍑虹幇閿欒
-     *
-     * @param session
-     * @param error
      */
     @OnError
     public void onError(Session session, Throwable error) {
@@ -79,13 +76,13 @@
 
     /**
      * 鍙戦�佹秷鎭紝瀹炶返琛ㄦ槑锛屾瘡娆℃祻瑙堝櫒鍒锋柊锛宻ession浼氬彂鐢熷彉鍖栥��
-     *
-     * @param session
-     * @param message
      */
     public static void sendMessage(Session session, String message) {
         try {
-            session.getBasicRemote().sendText(String.format("%s", message));
+            // session.getAsyncRemote().sendText(message)
+            synchronized (session){
+                session.getBasicRemote().sendText(message);
+            }
         } catch (Exception ex) {
             log.error("鍙戦�佹秷鎭嚭閿欙細{}", ex.getMessage());
         }
@@ -93,9 +90,6 @@
 
     /**
      * 缇ゅ彂娑堟伅
-     *
-     * @param message
-     * @throws IOException
      */
     public static void broadCastInfo(String message) throws IOException {
         for (Session session : SESSION_SET) {
@@ -107,10 +101,6 @@
 
     /**
      * 鎸囧畾Session鍙戦�佹秷鎭�
-     *
-     * @param sessionId
-     * @param message
-     * @throws IOException
      */
     public static void sendMessage(String message, String sessionId) throws IOException {
         Session session = null;
diff --git a/src/main/java/com/moon/server/service/data/RasterAnalysisService.java b/src/main/java/com/moon/server/service/data/RasterAnalysisService.java
index 51d5db6..58db30b 100644
--- a/src/main/java/com/moon/server/service/data/RasterAnalysisService.java
+++ b/src/main/java/com/moon/server/service/data/RasterAnalysisService.java
@@ -74,7 +74,7 @@
             return;
         }
 
-        // for (PublishEntity pub : pubs) {
+        //for (PublishEntity pub : pubs) {
         pubs.parallelStream().forEach(pub -> {
             try {
                 AnalysisResultEntity entity = new AnalysisResultEntity(token);
@@ -137,6 +137,7 @@
 
         String json = JSONObject.toJSONString(map);
         // System.out.println(json)
+
         WebSocketService.broadCastInfo(json);
     }
 
diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml
index c04d2c7..e106e61 100644
--- a/src/main/resources/application.yml
+++ b/src/main/resources/application.yml
@@ -46,12 +46,12 @@
   datasource:
     name: prod
     # JDBC 鍩烘湰閰嶇疆 &currentSchema=public
-    url: jdbc:postgresql://127.0.0.1:5433/moon?useAffectedRows=true
-    #url: jdbc:postgresql://192.168.20.83:5433/moon?useAffectedRows=true
+    #url: jdbc:postgresql://127.0.0.1:5433/moon?useAffectedRows=true
+    url: jdbc:postgresql://192.168.20.83:5433/moon?useAffectedRows=true
     #url: jdbc:postgresql://103.85.165.99:25432/moon?useAffectedRows=true
     username: postgres
-    #password: Postgres!_14_moon
-    password: postgres
+    password: Postgres!_14_moon
+    #password: postgres
     driver-class-name: org.postgresql.Driver
     platform: POSTGRESQL
     type: com.alibaba.druid.pool.DruidDataSource

--
Gitblit v1.9.3