解决nacos异常,发送客户端当只有空格是不推送

This commit is contained in:
wulin 2023-10-21 10:08:24 +08:00
parent ac23efe3a0
commit 62fba7e356
2 changed files with 21 additions and 7 deletions

View File

@ -75,6 +75,12 @@
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
<!-- https://mvnrepository.com/artifact/com.github.ben-manes.caffeine/caffeine -->
<dependency>
<groupId>com.github.ben-manes.caffeine</groupId>
<artifactId>caffeine</artifactId>
<version>3.1.8</version>
</dependency>
</dependencies> </dependencies>

View File

@ -134,15 +134,19 @@ public class BaseWebSocketProcess {
int m = Math.max(Math.max(Math.max(Math.max(d, j), Math.max(a, b)), c), n); int m = Math.max(Math.max(Math.max(Math.max(d, j), Math.max(a, b)), c), n);
if (m > 0) { if (m > 0) {
//清空 //清空
String msg = old.substring(0, m);
if(msg.replace(" ", "").length() > 0){
//纯空格的不推送
sb.setLength(0); sb.setLength(0);
sb.append(old.substring(m)); sb.append(old.substring(m));
old = old.substring(0, m);
normalSendMsg(baseSession, old, type, YesNo.NO.getCode()); normalSendMsg(baseSession, msg, type, YesNo.NO.getCode());
} else { return;
sb.append(message);
} }
}
sb.append(message);
return; return;
} }
log.info("已经有新的请求不在推送到客户端SN{} userId:{}", baseSession.getSn(), baseSession.getUserId()); log.info("已经有新的请求不在推送到客户端SN{} userId:{}", baseSession.getSn(), baseSession.getUserId());
@ -152,7 +156,11 @@ public class BaseWebSocketProcess {
@Override @Override
public void finish() { public void finish() {
log.info("千问最后调用finish"); log.info("千问最后调用finish");
String msg = sb.toString();
if(msg.replace(" ", "").length() > 0){
//纯空格的不推送
normalSendMsg(baseSession, sb.toString(), type); normalSendMsg(baseSession, sb.toString(), type);
}
MDC.remove(Log4Constans.PRINT_LOG_ID); MDC.remove(Log4Constans.PRINT_LOG_ID);
} }
}).flatMap(data ->{ }).flatMap(data ->{