The issue
I've got a Rest API in Spring-Boot where i'm listening to an event-source stream from html
like so:
eventSource = new EventSource("/api/events/receive", {
xhrHeaders: {
'Content-Type': 'text/event-stream',
'Connection': 'keep-alive'
}
});
eventSource.onmessage = function (evt) { ... };
The EventSource returns 503 after a while!
Works perfectly on localhost but not on remote host!
Things i've tried
- add keep-alive on the
@RestController
viaHttpServletResponse
Object
@GetMapping(path = "/api/events/receive", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
public Flux<Ambulance> receiveAmbulance(HttpServletResponse resp) {
resp.addHeader("Connection", "keep-alive");
return Flux.create(sink -> {
ambulanceProcessor.register(sink::next);
});
}
- add to that template a
keep-alive
header via@Controller
@GetMapping("/dashboard")
public String getResource(Model model, HttpServletResponse response) {
response.addHeader("Connection", "keep-alive");
return "view";
}
Related posted i've visited
503 After a few seconds
Note: I've tried almost everything and nothing seems to work for me...