Spring Boot将通知推送到vue.js

问题描述

我想向使用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 (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...