Alexandre Victoor
Architecte à la SGCIB
alexvictoor@gmail.com
https://github.com/alexvictoor
@alex_victoor
GET /mystream HTTP/1.1 Host: localhost Accept: text/event-stream
HTTP/1.1 200 OK Connection: keep-alive Content-Type: text/event-stream Transfer-Encoding: chunked
HTTP/1.1 200 OK Connection: keep-alive Content-Type: text/event-stream Transfer-Encoding: chunked data: un premier événement, du txt ou n'importe quoi
HTTP/1.1 200 OK Connection: keep-alive Content-Type: text/event-stream Transfer-Encoding: chunked data: un premier événement, du txt ou n'importe quoi data: un deuxième data: sur data: plusieurs data: lignes
HTTP/1.1 200 OK Connection: keep-alive Content-Type: text/event-stream Transfer-Encoding: chunked data: un premier événement, du txt ou n'importe quoi data: un deuxième data: sur data: plusieurs data: lignes data: {"msg": "un troisieme en json"}
var source = new EventSource("http://localhost:8081/stream");
source.onmessage = function(event) {
// console.log(event.data);
};
id: 123 event: TaskCompleted data: avec un id (123) data: et un type (TaskCompleted)
var source = new EventSource("http://localhost:8081/stream");
source.addEventListener("TaskCompleted", function (event) {
// console.error(event.data);
});
id: 123 data: dernier événement reçu ===== coupure =====
id: 123 data: dernier événement reçu ===== coupure ===== GET /mystream HTTP/1.1 Host: localhost Accept: text/event-stream Last-Event-ID: 123
HTTP/1.1 200 OK Connection: keep-alive Content-Type: text/event-stream Transfer-Encoding: chunked retry: 5000 data: { ... }
@GET
@Produces(SseFeature.SERVER_SENT_EVENTS)
public EventOutput getMyStream() {
EventOutput eventOutput = new EventOutput();
// ...
return eventOutput
}
eventOutput.write(event);