<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


    只有注冊用戶登錄后才能發(fā)表評論。


    網(wǎng)站導(dǎo)航:
     
    主站蜘蛛池模板: 国产成人精品一区二区三区免费| 亚洲日本VA午夜在线电影| 亚洲精品午夜无码电影网| 精品亚洲视频在线观看| 亚洲国产高清在线一区二区三区| 一区二区三区亚洲视频| 免费人成年激情视频在线观看| 免费a级毛片大学生免费观看| 国产片免费福利片永久| 免费日本黄色网址| 亚洲国产婷婷综合在线精品| 中文字幕亚洲综合久久男男| 亚洲精品无码乱码成人| 亚洲AV人无码综合在线观看| 亚洲视频免费一区| 亚洲在成人网在线看| 亚洲人成网国产最新在线| 亚洲av最新在线观看网址| 老外毛片免费视频播放| 黄桃AV无码免费一区二区三区 | 久久九九亚洲精品| 久久丫精品国产亚洲av| 亚洲福利一区二区三区| 亚洲一本一道一区二区三区| 狠狠入ady亚洲精品| 久久国产乱子伦精品免费午夜 | 日韩欧美亚洲国产精品字幕久久久 | 亚洲黄色网站视频| 亚洲日韩乱码久久久久久| 亚洲色少妇熟女11p| 亚洲av无码兔费综合| 亚洲天堂免费在线视频| 午夜免费啪视频在线观看| 日韩视频在线观看免费| 波多野结衣免费在线观看| 国产男女猛烈无遮档免费视频网站 | 久久久精品2019免费观看| 亚洲第一成年免费网站| 国产又粗又猛又爽又黄的免费视频 | 亚洲国产综合第一精品小说| 亚洲国产AV无码一区二区三区|