<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 閱讀(340) 評論(0)  編輯  收藏 所屬分類: REACTIVE STREAMS

    主站蜘蛛池模板: 亚洲AV日韩AV鸥美在线观看| 精品一区二区三区高清免费观看| 免费国产黄网站在线看| 免费无码VA一区二区三区| 久久久久亚洲精品无码网址| 亚洲a视频在线观看| 免费萌白酱国产一区二区三区| 四虎永久在线精品免费观看地址| 亚洲最大视频网站| 91福利视频免费| 亚洲AV中文无码字幕色三| 色多多A级毛片免费看| 日本媚薬痉挛在线观看免费| 亚洲大香人伊一本线| 哒哒哒免费视频观看在线www| 国产亚洲精品成人AA片| 久久久久久国产a免费观看黄色大片| 91久久亚洲国产成人精品性色| 免费成人高清在线视频| 亚洲日本va在线视频观看| 久久99精品免费一区二区| 亚洲午夜久久久久久尤物| 成人女人A级毛片免费软件| 亚洲国产成人久久精品app| 久久亚洲高清综合| AV免费网址在线观看| 亚洲av日韩精品久久久久久a| 麻豆国产VA免费精品高清在线| 亚洲AV无码国产一区二区三区| 久久亚洲精品无码| 成人亚洲综合天堂| 日本精品久久久久久久久免费 | 亚洲欧洲日产国码www| yy6080亚洲一级理论| 和日本免费不卡在线v| 成在人线av无码免费高潮喷水| 麻豆安全免费网址入口| 国产午夜亚洲精品国产成人小说| 成人免费无码视频在线网站| 57pao国产成视频免费播放| 亚洲偷自拍另类图片二区|