我通过 websockets 连接到 Spring-Boot 服务器,通过 uuid 接收特定设备的日志。
日志StompConfig.ts
import { StompConfig } from '@stomp/ng2-stompjs';
import * as SockJS from 'sockjs-client';
export const logsStompConfig: StompConfig = {
url: () => new SockJS('http://localhost:9000/gs-guide-websocket'),
headers: {},
heartbeat_in: 0,
heartbeat_out: 20000,
reconnect_delay: 1000,
debug: false
};
Run Code Online (Sandbox Code Playgroud)
日志.service.ts
import { Injectable } from '@angular/core';
import { StompService } from "@stomp/ng2-stompjs";
import { Message } from "@stomp/stompjs";
import { Observable } from "rxjs/Observable";
@Injectable()
export class LogsService {
private stomp_subscription: Observable<Message>;
constructor(private stompService: StompService) {
this.stomp_subscription …Run Code Online (Sandbox Code Playgroud)