Spring boot Spring boot webflux文本\事件\流\值不工作

Spring boot Spring boot webflux文本\事件\流\值不工作,spring-boot,spring-webflux,Spring Boot,Spring Webflux,我使用的是spring boot和依赖项spring boot starter webflux, 我想用浏览器每秒获取一个数据, 当我使用spring boot版本2.1.4时,代码正在运行, 但2.1.5或更高版本不起作用, 我将在10秒后获得所有数据,而不是每秒一个数据 I want to get the reason,or others i should do I find spring-boot update the dependency of netty in 2.1.5, s

我使用的是spring boot和依赖项spring boot starter webflux, 我想用浏览器每秒获取一个数据, 当我使用spring boot版本2.1.4时,代码正在运行, 但2.1.5或更高版本不起作用, 我将在10秒后获得所有数据,而不是每秒一个数据

I want to get the reason,or others i should  do 


I find spring-boot update the dependency of netty in 2.1.5,
so if i add the dependency in my pom.xml with 
<dependency>
    <groupId>io.projectreactor.netty</groupId>
    <artifactId>reactor-netty</artifactId>
    <version>0.8.8.RELEASE</version>
 </dependency>

it working


@RestController
@RequestMapping("/demo")
public class DemoController {
    // just get a string per second
    @GetMapping(value = "",produces = MediaType.TEXT_EVENT_STREAM_VALUE)
    public Flux<String>  getMsg(){
       return Flux.fromStream(new Random().ints(10).mapToObj(intStream -> 
       {
           try {
               TimeUnit.SECONDS.sleep(1);
           } catch (InterruptedException e) {
               e.printStackTrace();
           }
           return "this is data "+intStream;
       }));
    }
}
我想知道原因,或者其他我应该做的事情
我发现spring boot在2.1.5中更新了netty的依赖性,
因此,如果我在pom.xml中添加依赖项
伊奥·内蒂
反应堆网
0.8.8.1发布
它在工作吗
@RestController
@请求映射(“/demo”)
公共类DemoController{
//每秒只需获取一个字符串
@GetMapping(value=”“,products=MediaType.TEXT\u事件\u流\u值)
公共流量getMsg(){
返回Flux.fromStream(new Random().ints(10).mapToObj(intStream->
{
试一试{
时间单位。秒。睡眠(1);
}捕捉(中断异常e){
e、 printStackTrace();
}
返回“这是数据”+intStream;
}));
}
}

我相信这将实现您的目标

@GetMapping(value = "",produces = MediaType.TEXT_EVENT_STREAM_VALUE)
public Flux<String> getMsg(){
    return Flux.fromStream(new Random()
            .ints(10)
            .mapToObj(value -> "this is data " + value))
            .delayElements(Duration.ofSeconds(1));
}
@GetMapping(value=”“,products=MediaType.TEXT\u EVENT\u STREAM\u value)
公共流量getMsg(){
返回通量.fromStream(新的Random()
.ints(10)
.mapToObj(值->“这是数据”+值))
.延迟元素(持续时间为秒(1));
}

您可以使用通量的
delayElements
操作符。这更适合反应式,因为它不会阻塞。谢谢,我将延迟时间设置为0。我一次得到一个数据ai,而不是最后得到的所有数据。我仍然对此感到困惑,不确定我做错了什么。我的情况与此类似,数据一次全部出现,但不是以1秒的间隔出现。以下是链接: