首页 > 解决方案 > 如何订阅具有路径变量 Spring boot - Angular - Websocket - 的端点

问题描述

我正在关注几篇文章,但无法解决我的情况

场景:用户应该能够订阅具有路径变量的端点

https://spring.io/guides/gs/messaging-stomp-websocket/

https://roytuts.com/spring-boot-websocket-angularjs-gradle-example/

用法:用户将打开一个引用自定义角度组件的链接

https://github.com/roytuts/websocket/blob/master/Spring-WebSocket/angular-spring-websocket/src/app/app.component.ts

  constructor(private title: Title){
    this.connection();
  }
  
  connection(){
    let ws = new SockJS(this.url);
    this.client = Stomp.over(ws);
    let that = this;
    
    this.client.connect({}, function(frame) {
      that.client.subscribe("/topic/greeting", (message) => {
        if(message.body) {
          this.greeting = message.body;       
          $(".msg").html(this.greeting)       
        }
      });
    });
  }

错误:哎呀!失去与 http://localhost:8081/.../something/89 的连接

11-10-2021 18:15:23.490 [35m[http-nio-8080-exec-3][0;39m [39mDEBUG[0;39m o.s.web.servlet.DispatcherServlet.traceDebug - GET "/api/..../89/info?t=1633972523472", parameters={masked}
11-10-2021 18:15:23.491 [35m[http-nio-8080-exec-3][0;39m [39mDEBUG[0;39m o.s.w.s.h.SimpleUrlHandlerMapping.getHandler - Mapped to ResourceHttpRequestHandler [Classpath [META-INF/resources/], Classpath [resources/], Classpath [static/], Classpath [public/], ServletContext [/]]
11-10-2021 18:15:23.492 [35m[http-nio-8080-exec-3][0;39m [39mDEBUG[0;39m o.s.o.j.s.OpenEntityManagerInViewInterceptor.preHandle - Opening JPA EntityManager in OpenEntityManagerInViewInterceptor
11-10-2021 18:15:23.502 [35m[http-nio-8080-exec-3][0;39m [39mDEBUG[0;39m o.s.w.s.r.ResourceHttpRequestHandler.handleRequest - Resource not found

默认情况下 info?t=1633972523472 被添加,似乎这给了 404 not found

我想要的是订阅端点应该是动态的 - /topic/greeting/group10 或 /topic/greeting/group20 等或任何其他模型,如请求正文获取带有 groupid 的 json

如何创建许多不同的主题?请帮忙

标签: angularspring-bootwebsocket

解决方案


推荐阅读