Angular : RxStomp 감시, 구성, 활성화 방법

Nov 20 2020

Stomp에서는 다음과 같은 방법을 사용했습니다.

initUserEvents() {

this.stompService.startConnect().then(() => {
      this.stompService.done('init');

this.stompService.subsribe('/channel/login', res => {
      if (res.username !== this.username) {

        this.newConnectedAccounts.push(res.username);

지금은 RxStomp로 작업 중이며 이러한 "대체"방법을 사용하는 올바른 방법을 찾을 수 없습니다.

initUserEvents() {

this.stompService.configure();
    this.stompService.activate(){

    this.stompService.watch('/channel/login', res => {
      if (res.username !== this.username) {
        this.newConnectedAccounts.push(res.username);

내가받는 오류 : TS2345 : '(res : any) => void'형식의 인수가 'StompHeaders'형식의 매개 변수에 할당 할 수 없습니다. 색인 서명이 '(res : any) => void'유형에 없습니다.

답변

JustinBertram Nov 20 2020 at 14:59

RxStomp 문서를 살펴보십시오. 그것은 말한다 :

주요 차이점은 작업을 RxJS Observable로 노출한다는 것입니다. 예를 들어 STOMP 엔드 포인트가 구독되면 수신 된 모든 메시지를 스트리밍하는 Observable을 반환합니다.

beforeConnect를 제외하고 @ stomp / stompjs 클라이언트의 모든 콜백과 관련된 기능 은 Observables / Subjects / BehaviorSubjects로 노출됩니다.

즉, watch메서드에 콜백을 전달하지 않습니다 . Observable메시지를 가져 오는 데 사용할 수 있는를 반환 합니다.

RxStomp API는 watch콜백이 아닌 헤더를 메소드 에 전달할 것으로 예상합니다 . 그것이 당신에게 구체적으로 말하는 이유입니다.

TS2345: Argument of type '(res: any) => void' is not assignable to parameter of type 'StompHeaders'.