use of io.micronaut.http.client.docs.streaming.Headline in project micronaut-core by micronaut-projects.
the class HeadlineController method streamHeadlines.
// tag::streaming[]
// <1>
@Get(value = "/headlines", produces = MediaType.TEXT_EVENT_STREAM)
Flux<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.http.client.docs.streaming.Headline in project micronaut-core by micronaut-projects.
the class HeadlineControllerTest 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 = headlineClient.streamHeadlines().blockFirst();
Assertions.assertNotNull(headline);
Assertions.assertTrue(headline.getData().getText().startsWith("Latest Headline"));
}
}
Aggregations