<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    paulwong

    SPRING REACTOR 使用樣例

    SpringReactorTest.java

    package com.paul.testreactivestream.reactor;


    import java.util.List;

    import org.junit.jupiter.api.Test;

    import reactor.core.publisher.Flux;
    import reactor.core.publisher.Mono;
    import reactor.core.scheduler.Schedulers;

    public class SpringReactorTest {
        
        private void subscribeAndEnd(Flux<?> flux) {
            
            flux.map(c -> String.format("[%s] %s", Thread.currentThread().getName(), c))
                .subscribe(System.out::println);
            
            flux.blockLast();
        }
        
        @Test
        public void createAFlux_just() throws InterruptedException {
            Flux<String> fruitFlux = 
                    Flux.just("Apple", "Orange", "Grape", "Banana", "Strawberry")
                        .log()
                        ;
            fruitFlux.subscribe(
                         f -> System.out.println(
                                     String.format("[%s] Here's some fruit: %s", Thread.currentThread().getName(), f)
                                 )
                      )
                     ;
            fruitFlux.blockLast();
            
    //        Thread.currentThread().join();
        }
        
        @Test
        public void zipFluxesToObject() {
            Flux<String> characterFlux = 
                    Flux.just("Garfield", "Kojak", "Barbossa");
            
            Flux<String> foodFlux = 
                    Flux.just("Lasagna", "Lollipops", "Apples");
            
            Flux<String> zippedFlux = 
                    Flux.zip(characterFlux, foodFlux, (c, f) -> c + " eats " + f);
            
            this.subscribeAndEnd(zippedFlux);
        }
        
        @Test
        public void map() {
            Flux<Player> playerFlux = 
                    Flux.just("Michael Jordan", "Scottie Pippen", "Steve Kerr")
                        .map(n -> {
                            String[] split = n.split("\\s");
                            return new Player(split[0], split[1]);
                        })
                        ;
            this.subscribeAndEnd(playerFlux);
        }
        
        @Test
        public void flatMap() {
            Flux<Player> playerFlux = 
                    Flux.just("Michael Jordan", "Scottie Pippen", "Steve Kerr")
                        .flatMap(
                            n -> Mono.just(n)
                                     .map(p -> {
                                        String[] split = p.split("\\s");
                                        return new Player(split[0], split[1]);
                                      })
                                     .subscribeOn(Schedulers.parallel())
                         );
            this.subscribeAndEnd(playerFlux);
        }
        
        @Test
        public void buffer() {
            Flux<List<String>> fruitFlux = 
                    Flux.just(
                            "apple", "orange", "banana", "kiwi", "strawberry"
                         )
                        .buffer(3);
            this.subscribeAndEnd(fruitFlux);
        }
        
        @Test
        public void bufferAsyn() {
            Flux<String> flux =
                Flux.just(
                        "apple", "orange", "banana", "kiwi", "strawberry"
                     )
                    .buffer(3)
                    .flatMap(x ->
                        Flux.fromIterable(x)
                            .map(y -> y.toUpperCase())
                            .subscribeOn(Schedulers.parallel())
        //                    .log()
                     );
            this.subscribeAndEnd(flux);
        }
        
        @Test
        public void all() {
            Mono<Boolean> animalFlux = 
                    Flux.just(
                            "aardvark", "elephant", "koala", "eagle", "kangaroo"
                         )
                        .all(c -> c.contains("a"))
                        ;
            animalFlux.map(c -> String.format("[%s] %s", Thread.currentThread().getName(), c))
                      .subscribe(System.out::println);
        
        }

    }

    posted on 2021-11-23 13:59 paulwong 閱讀(335) 評論(0)  編輯  收藏 所屬分類: REACTIVE STREAMS

    主站蜘蛛池模板: 国产亚洲精品美女2020久久| 亚洲日本一区二区三区在线| 成年女人免费v片| 老司机在线免费视频| 久久精品免费全国观看国产| 97性无码区免费| 国产免费av片在线看| 麻豆精品国产免费观看| 日美韩电影免费看| 成人亚洲网站www在线观看| 亚洲国产精品第一区二区三区| 亚洲人成网站观看在线播放| 中文字幕在亚洲第一在线| 国产成A人亚洲精V品无码性色| 亚洲av片劲爆在线观看| 亚洲麻豆精品果冻传媒| 国产婷婷综合丁香亚洲欧洲| 亚洲成在人线在线播放无码| 老司机午夜在线视频免费| 二个人看的www免费视频| 久久成人无码国产免费播放| 亚洲大片免费观看| 好大好深好猛好爽视频免费| 四虎永久免费地址在线网站| 亚洲综合国产一区二区三区| 亚洲人成影院在线| 亚洲一本到无码av中文字幕| 美女扒开屁股让男人桶爽免费| caoporn成人免费公开| 99爱视频99爱在线观看免费| 色妞WWW精品免费视频| va亚洲va日韩不卡在线观看| 亚洲高清国产AV拍精品青青草原| 97se亚洲综合在线| 亚洲heyzo专区无码综合| 国产日韩AV免费无码一区二区三区| 国产精品免费观看调教网| 久久久www成人免费毛片| 亚洲中文字幕无码爆乳av中文| 亚洲欧洲日韩国产综合在线二区| 中文字幕精品三区无码亚洲|