FluxMonoController.java 784 Bytes
package com.krunal.reactive.controller;


import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;

import java.time.Duration;

@RestController
public class FluxMonoController {


    @GetMapping("/flux")
    public Flux<Integer> returnFlux(){
        return Flux.just(1,2,3,4,5,6)
                //.delayElements(Duration.ofSeconds(1))
                .log();
    }

    @GetMapping(value = "/fluxStream",produces = MediaType.APPLICATION_STREAM_JSON_VALUE)
    public Flux<Integer> returnFluxWithStreamTypeJson(){
        return Flux.just(1,2,3,4,5,6)
                .delayElements(Duration.ofSeconds(1))
                .log();
    }
}