总结:
- 广播式:通知所有人,简单。只需要订阅一个地址就行。
- 特定用户: 2种做法。
- 每个人订阅的地址不一样。
- 编程式获得websocket,然后操作它就行了。
这里我采用编程式使用。
- 配置bean:
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.EnableWebSocketMessage