sseBuilder.comment(comment.toString().substring(0, comment.length() - 1));
sseBuilder.comment(comment.toString().substring(0, comment.length() - 1));
@GetMapping("/event") Flux<ServerSentEvent<Person>> sse() { return INTERVAL.take(2).map(l -> ServerSentEvent.builder(new Person("foo " + l)) .id(Long.toString(l)) .comment("bar " + l) .build()); }
sseBuilder.comment(comment.toString().substring(0, comment.length() - 1));
sseBuilder.comment(comment.toString().substring(0, comment.length() - 1));
@RequestMapping("/sse/event") Flux<ServerSentEvent<String>> sse() { return INTERVAL.map(l -> ServerSentEvent.builder("foo") .id(Long.toString(l)) .comment("bar") .build()); }
@Test public void writeServerSentEvent() { ServerSentEvent<?> event = ServerSentEvent.builder().data("bar").id("c42").event("foo") .comment("bla\nbla bla\nbla bla bla").retry(Duration.ofMillis(123L)).build(); Mono<ServerSentEvent> source = Mono.just(event); testWrite(source, outputMessage, ServerSentEvent.class); StepVerifier.create(outputMessage.getBody()) .consumeNextWith(stringConsumer("id:c42\nevent:foo\nretry:123\n:bla\n:bla bla\n:bla bla bla\ndata:")) .consumeNextWith(stringConsumer("bar\n")) .consumeNextWith(stringConsumer("\n")) .expectComplete() .verify(); }
Mono<ServerResponse> sse(ServerRequest request) { Flux<ServerSentEvent<String>> body = INTERVAL .map(aLong -> ServerSentEvent.builder("foo").id("" + aLong).comment("bar").build()); return ServerResponse.ok().body(fromServerSentEvents(body)); } }