Angular 2 stomp服务消耗

时间:2017-12-18 20:15:06

标签: typescript observable stomp

我得到responseBody未定义,但我在msg_body中获得了订阅响应。问题与responseBody有什么关系?

 let stomp_subscription = this._stompService.subscribe('/topic/queue');
stomp_subscription.map((message: Message) => {
  return message.body;
}).subscribe((msg_body: string) => {
  console.log(`Received: ${msg_body}`);
  this.responseBody = JSON.parse(msg_body);
  console.log('RESPONSECODE' + this.responseBody.ResponseInfo.ResponseCode);
});

1 个答案:

答案 0 :(得分:0)

您正在使用来自Observable的return运算符的.map()语句。因此,该值不会传递给针对Observable的下一个.subscribe()调用。你能试试下面的代码

吗?
    let stomp_subscription = this._stompService.subscribe('/topic/queue');
    stomp_subscription.map((message: Message) => message.body )
     .subscribe((msg_body: string) => {
      console.log(`Received: ${msg_body}`);
      this.responseBody = JSON.parse(msg_body);
      console.log('RESPONSECODE' + this.responseBody.ResponseInfo.ResponseCode);
    });