angular2 stomp无法从spring boot接收消息

时间:2016-11-14 07:41:21

标签: angular spring-boot stomp spring-websocket

我使用spring oauth2和angular2无状态安全性。

我可以向angular2客户端发送主题消息。但客户无法收到个人信息,为什么?

@Override
    public void configureMessageBroker(MessageBrokerRegistry config) {
        config.enableSimpleBroker("/topic", "/queue/");
        config.setApplicationDestinationPrefixes("/pcAngular2");
    }

发送方法:

@GetMapping("/front")
    public ResponseEntity s(){

String userId="da94470c-4e9b-4e86-990e-811666861fe6";

        simpMessagingTemplate.convertAndSendToUser(userId,
                "/queue/websocketAndMessage", "hello");

        return ResponseEntity.ok("ok");
    }
}

angular2 client:

const individulaSubUrl = '/user/queue/websocketAndMessage';

this.stompClient.subscribe(xdidianSubUrl, e=> {
          console.log(e.body);
          this.doWithWebsocket(e.body);
        })

和客户端日志:

stomp.js:134Opening Web Socket...
lang.js:114Angular 2 is running in the development mode. Call enableProdMode() to enable the production mode.
stomp.js:134 Web Socket Opened...
stomp.js:134 >>> CONNECT
X-CSRF-TOKEN:d0168a17-5cfa-4a1a-bdf1-d95cf2940688
accept-version:1.1,1.0
heart-beat:10000,10000


stomp.js:134 <<< CONNECTED
version:1.1
heart-beat:0,0


stomp.js:134 connected to server undefined
stomp.js:134 >>> SUBSCRIBE
id:sub-0
destination:/user/queue/websocketAndMessage
  

当我得到&#34; / front&#34;那是春天的召唤   &#34; simpMessagingTemplate.convertAndSendToUser&#34;方法。

     

但angular2客户端没有收到预期的消息。

0 个答案:

没有答案