Code for eval article

This commit is contained in:
Michael Pratt 2018-04-17 17:04:06 -06:00
parent 7140229ca0
commit e69b630923
5 changed files with 63 additions and 0 deletions

View File

@ -0,0 +1,12 @@
package com.baeldung.demo.eventstreamwebfluxdemo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class EventStreamServer {
public static void main(String[] args) {
SpringApplication.run(EventStreamServer.class, args);
}
}

View File

@ -0,0 +1,18 @@
package com.baeldung.demo.eventstreamwebfluxdemo.client;
import org.springframework.http.MediaType;
import org.springframework.web.reactive.function.client.WebClient;
public class EventStreamClient {
public static void main(String[] args)
{
WebClient.create("http://127.0.0.1:8080")
.get()
.uri("/events")
.accept(MediaType.APPLICATION_STREAM_JSON)
.retrieve()
.bodyToFlux(Long.class)
.toStream()
.forEach(item -> System.out.println("New event : " + item));
}
}

View File

@ -0,0 +1,17 @@
package com.baeldung.demo.eventstreamwebfluxdemo.controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;
import java.time.Duration;
@RestController
public class EventStreamController
{
@RequestMapping("/events")
public Flux<Long> getServerEvents()
{
return Flux.interval(Duration.ofMillis(1000));
}
}

View File

@ -0,0 +1,16 @@
package com.baeldung.demo.eventstreamwebfluxdemo;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@SpringBootTest
public class EventStreamServerTests {
@Test
public void contextLoads() {
}
}