springboot webflux flux 使用示例(創建操作)


springboot webflux flux 使用示例(創建操作)

 

 

*************************

just、defer

 

public class Test {

    public static void main(String[] args) throws Exception{
        Flux.defer(() -> Flux.just("hello world "+System.currentTimeMillis()))
                .delaySubscription(Duration.ofSeconds(2))
                .subscribe(s -> {
                    System.out.println(s);
                    System.out.println("hello world "+System.currentTimeMillis());
                });

        Flux.just("hello world2 "+System.currentTimeMillis())
                .delaySubscription(Duration.ofSeconds(2))
                .subscribe(s -> {
                    System.out.println(s);
                    System.out.println("hello world2 "+System.currentTimeMillis());
                });

        TimeUnit.SECONDS.sleep(6);
    }
}

 

********************

控制檯輸出

 

hello world 1593229538551
hello world 1593229538555
hello world2 1593229536538
hello world2 1593229538555

defer當訂閱的時候創建flux對象流,just立刻創建對象流

 

 

 

 

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章