问题描述
我想向使用websocket和webstomp连接的所有客户端发送通知,因此当向数据库中添加某些行时,我需要推送通知,我尝试了类似的操作,但没有用
我的套接字配置
@Configuration
@EnableWebSocketMessageBroker
public class WebSocketConfiguration extends AbstractWebSocketMessageBrokerConfigurer {
@Override
public void registerStompEndpoints(StompEndpointRegistry stompEndpointRegistry) {
stompEndpointRegistry.addEndpoint("/socket")
.setAllowedOrigins("*")
.withSockJS();
}
@Override
public void configureMessageBroker(MessageBrokerRegistry registry) {
registry.enableSimpleBroker("/topic");
registry.setApplicationDestinationPrefixes("/app");
}
}
控制器
template.convertAndSend("/topic/notification",position);
前
methods: {
connect() {
this.socket = new SockJS("http://localhost:8082/socket");
this.stompClient = Stomp.over(this.socket);
this.stompClient.connect({},frame => {
this.connected = true;
console.log(frame);
this.stompClient.subscribe("/topic/notification",tick => {
console.log(tick);
this.$notify({
group: 'foo',title: '<h4>Nothing!</h4>',text: 'car added',type: 'success',duration: 1000
})
});
},error => {
console.log(error);
this.connected = false;
}
);
},},
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)