woyao396
V2EX  ›  问与答

关于 springboot 中使用 websocket 的疑问?

  •  
  •   woyao396 · Mar 2, 2021 · 1874 views
    This topic created in 1912 days ago, the information mentioned may be changed or developed.

    现在网上资料大多有 2 种使用方式:

    1. 使用 @ServerEndpoint("/hello") 然后用如下注解放在方法是

    2.使用 spring 官方文档基于STOMP 的方案

    https://spring.io/guides/gs/messaging-stomp-websocket/

    想问一下这 2 者的区别,依赖情况,以及那种是最优方案?

    现在需要解决的业务问题是:后端实时向前端推送执行 shell 脚本的日志

    3 replies    2021-03-02 14:10:15 +08:00
    themostlazyman
        1
    themostlazyman  
       Mar 2, 2021
    定时执行的话,建议轮询。
    Smilencer
        2
    Smilencer  
       Mar 2, 2021
    STOMP 将 WS 包装了下,把 ws 的报文按照一定的规范来交互。 如果只是后端给前端日志推送这一个交互的话,建议直接用 ws 就行了,前端会感谢你。
    badbye
        3
    badbye  
       Mar 2, 2021
    stomp 貌似只支持文本,前端有现成的库
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   4365 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 32ms · UTC 00:10 · PVG 08:10 · LAX 17:10 · JFK 20:10
    ♥ Do have faith in what you're doing.