什么是stomp
STOMP(Simple(or Streaming)Text Orientated Messaging Protocol)是一个简单的文本协议,它定义了客户端和消息代理之间进行通信的格式。它是一种可互操作的协议,因为许多不同的消息代理和客户端都实现了它。 STOMP提供了一种可靠的,异步的消息传递模型,它适用于在异构系统之间进行通信,例如在使用不同编程语言编写的系统之间进行通信。 STOMP协议由于其简单性和可互操作性而变得越来越流行。
代码示例大纲
后端发布socket消息订阅频道
前端连接后端socket
一个前端发送消息,多个前端同时收到消息
后端代码
启用websocket "/endpointWisely",生成订阅频道“/topic”
package com.websocket;
import org.springframework.context.annotation.Configuration;
import org.springframework.messaging.simp.config.MessageBrokerRegistry;
import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker;
import org.springframework.web.socket.config.annotation.StompEndpointRe