成功连接到服务器并成功订阅后无法获取消息
没有看到任何错误,一切都很好,但是更新不起作用
可以在浏览器中看到http://....../testdata个对象数组
module.ts
import {RawDataComponent} from './components/rawdata/rawdata.component';
import {StatusComponent} from './components/status/status.component';
import {StompConfig, StompService} from '@stomp/ng2-stompjs';
const stompConfig: StompConfig = {
url: 'ws://...../ws',
headers: {
},
heartbeat_in: 0, // Typical value 0 - disabled
heartbeat_out: 20000, // Typical value 20000 - every 20 seconds
reconnect_delay: 5000,
debug: true
};
....
providers: [
StompService,
{
provide: StompConfig,
useValue: stompConfig
}
],
.....
rawdata.component.ts
import { Component, OnInit, OnDestroy } from '@angular/core';
import { Observable } from 'rxjs/Observable';
import {Message} from '@stomp/stompjs';
import { Subscription } from 'rxjs/Subscription';
import {StompService} from '@stomp/ng2-stompjs';
private subscription: Subscription;
public messages: Observable<Message>;
public subscribed: boolean;
/** Constructor */
constructor(private _stompService: StompService) { }
ngOnInit() {
this.messages = this._stompService.subscribe('/testdata');
this.subscription = this.messages.subscribe(this.on_next);
}
public on_next = (message: Message) => {
console.log('message ', message);
}
在控制台中
Tue Oct 02 2018 20:12:44 GMT+0300 (Москва, стандартное время) "connected to server undefined"
stomp.service.ts:271 Tue Oct 02 2018 20:12:44 GMT+0300 (Москва, стандартное время) "Connected"
stomp.service.ts:271 Tue Oct 02 2018 20:12:44 GMT+0300 (Москва, стандартное время) "Will try sending queued messages "
stomp.service.ts:271 Tue Oct 02 2018 20:12:44 GMT+0300 (Москва, стандартное время) "Will subscribe to /testdata"
stomp.service.ts:271 Tue Oct 02 2018 20:12:44 GMT+0300 (Москва, стандартное время) ">>> SUBSCRIBE
ack:auto
id:sub-0
destination:/testdata