总结:
- 广播式:通知所有人,简单。只需要订阅一个地址就行。
- 特定用户: 2种做法。
- 每个人订阅的地址不一样。
- 编程式获得websocket,然后操作它就行了。
这里我采用编程式使用。
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.messaging.simp.config.MessageBrokerRegistry;
import org.springframework.web.socket.config.annotation.AbstractWebSocketMessageBrokerConfigurer;
import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker;
import org.springframework.web.socket.config.annotation.StompEndpointRegistry;
/**
* 服务推送: wss://www.example.com/websocket/SendTo/topic/greetings
* 前端请求: wss://www.example.com/websocket/MessageMapping/topic/MessageMapping
* socket核心配置容器
*/
@Configuration
@EnableWebSocketMessageBroker
public class WebSocketConfig extends AbstractWe