use of io.micronaut.docs.streaming.Headline in project micronaut-core by micronaut-projects.
the class HeadlineController method streamHeadlines.
// tag::streaming[]
// <1>
@Get(value = "/headlines", processes = MediaType.TEXT_EVENT_STREAM)
Publisher<Event<Headline>> streamHeadlines() {
return Flux.<Event<Headline>>create((emitter) -> {
// <2>
Headline headline = new Headline();
headline.setText("Latest Headline at " + ZonedDateTime.now());
emitter.next(Event.of(headline));
emitter.complete();
}, FluxSink.OverflowStrategy.BUFFER).repeat(// <3>
100).delayElements(// <4>
Duration.of(1, ChronoUnit.SECONDS));
}
use of io.micronaut.docs.streaming.Headline in project micronaut-core by micronaut-projects.
the class HeadlineControllerSpec method testClientAnnotationStreaming.
// tag::streamingClient[]
@Test
public void testClientAnnotationStreaming() throws Exception {
try (EmbeddedServer embeddedServer = ApplicationContext.run(EmbeddedServer.class)) {
HeadlineClient headlineClient = embeddedServer.getApplicationContext().getBean(HeadlineClient.class);
Event<Headline> headline = Mono.from(headlineClient.streamHeadlines()).block();
assertNotNull(headline);
assertTrue(headline.getData().getText().startsWith("Latest Headline"));
}
}
Aggregations