月球大数据地理空间分析展示平台-【后端】-月球后台服务
13693261870
2023-10-26 c40fc0cc01b12f6fab6db90af395eb241e0e2aaf
解决WS消息推送报错
已修改3个文件
29 ■■■■■ 文件已修改
src/main/java/com/moon/server/service/all/WebSocketService.java 18 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/moon/server/service/data/RasterAnalysisService.java 3 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/application.yml 8 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
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 @@
    /**
     * 发送消息,实践表明,每次浏览器刷新,session会发生变化。
     *
     * @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;
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);
    }
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