diff --git a/spring-5-reactive/src/main/java/com/baeldung/reactive/controller/StockReactiveController.java b/spring-5-reactive/src/main/java/com/baeldung/reactive/controller/StockReactiveController.java deleted file mode 100644 index 8f8de79561..0000000000 --- a/spring-5-reactive/src/main/java/com/baeldung/reactive/controller/StockReactiveController.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.baeldung.reactive.controller; - -import java.math.BigDecimal; -import java.time.Duration; -import java.util.Random; -import java.util.stream.Stream; - -import org.springframework.http.MediaType; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; - -import com.baeldung.reactive.model.Stock; - -import reactor.core.publisher.Flux; -import reactor.util.function.Tuple2; - -@RestController -@RequestMapping("/rtes") -public class StockReactiveController { - - @GetMapping(produces = MediaType.TEXT_EVENT_STREAM_VALUE, value = "/stocks/{code}") - public Flux getStocks(@PathVariable String code) { - BigDecimal startingPrice = new BigDecimal("100"); - Flux stockFlux = Flux.fromStream(Stream.generate(() -> new Stock(code, getLatestPrice(startingPrice)))); - Flux emmitFlux = Flux.interval(Duration.ofSeconds(1)); - return Flux.zip(stockFlux, emmitFlux) - .map(Tuple2::getT1); - } - - private BigDecimal getLatestPrice(BigDecimal startingPrice) { - BigDecimal priceChange = BigDecimal.valueOf(new Random().nextDouble()); - return new Random().nextBoolean() ? startingPrice.add(priceChange) : startingPrice.subtract(priceChange); - } -}