Вызов SSE `this.eventSource.onmessage` не выполняется. Ошибка `" Ответ EventSource имеет тип MIME ("application / json"), который не является "text / event-stream" - PullRequest
0 голосов
/ 01 мая 2020

Сбой Angular Server Sent Event this.eventSource.onmessage вызывает ошибку "EventSource's response has a MIME type ("application/json") that is not "text/event-stream". Aborting the connection." Я вижу в Chrome Dev Tools (изображение прилагается), что возвращаются два Content-Type. Chrome DEv Tools Response Network Tab

Код бэкенда: пружинный реактор / REST

    @GetMapping(value="/events",produces = "text/event-stream;charset=UTF-8")
    public Flux<ConsumerEvent> getProductEvents(){
        return kafkaService.getReceiverRecordAllFlux()
                .map(record->
                    new ConsumerEvent(record.topic(),record.value())
                );
        }
}

Передний конец: Angular

public startKafkaTopicInfoEventSource(): void {
    let url = BASE_URL;
    this.eventSource = new EventSource(url); 
    this.eventSource.onmessage = (event) => {//Error: EventSource's response has a MIME type ("application/json") that is not "text/event-stream". Aborting the connection
        this.zone.run(() => {
        // some code here
      })

    }
// other code here
}

Метод this.eventSource.onmessage выдает ошибку EventSource's response has a MIME type ("application/json") that is not "text/event-stream". Aborting the connection.

Любая помощь будет отличной!

...