I use scheduleatfixedrate and sseemitter, but the front end only get message once.
my backend code is like this
var scheduledFuture =
sseExecutor.scheduleAtFixedRate(
() -> {
try {
SseEmitter.SseEventBuilder event =
SseEmitter.event()
.data("SSE MVC - " + LocalTime.now())
.id(String.valueOf(System.currentTimeMillis()))
.name("sse event - mvc");
emitter.send(event);
log.info("Sent SSE message at {}", LocalTime.now());
} catch (Exception ex) {
log.error("SSE error: {}", ex.getMessage(), ex);
emitter.completeWithError(ex);
}
},
0,
5,
TimeUnit.SECONDS);
and I can get the message from the curl as below
but from the browser chrome, it only get the first message after 5s, instead of keeping on push message to the browser
js code is like this
response = await fetch(sseUrl, {
method: 'GET',
headers: {
Accept: 'text/event-stream',
'Content-Type': 'application/json',
Authorization: `Bearer ${token}`,
'Cache-Control': 'no-cache',
},
signal: abortController.signal,
})