当前位置:   article > 正文

springboot集成websocket,服务端心跳检测_spring gateway 心跳检测

spring gateway 心跳检测
  1. @Component
  2. @EnableScheduling
  3. @Slf4j
  4. public class WebSocketHeartBeatTask {
  5. /**
  6. * 每10秒进行一次websocket心跳检测
  7. */
  8. @Scheduled(cron = "0/10 * * * * ?")
  9. public void beatTask() {
  10. AtomicInteger num = new AtomicInteger();
  11. SessionMgr.nativeSessions.values().stream().parallel().forEach(session->{
  12. try {
  13. session.sendMessage(new PingMessage());
  14. num.getAndIncrement();
  15. } catch (Exception e) {
  16. log.error("websocket心跳异常",e);
  17. }
  18. });
  19. log.info("websocket心跳检测结果,共【{}】个连接", num);
  20. }
  21. }

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/知新_RL/article/detail/717170
推荐阅读
相关标签
  

闽ICP备14008679号