第 4 章 对 Reactor 操作的解读

《Java编程方法论:响应式Spring Reactor 3设计与实现》学习笔记目录

笔记来源:《Java编程方法论:响应式Spring Reactor 3设计与实现》ISBN:9787121394768 作者:知秋 出版时间:2020年09月

4.1 filter 操作

1
2
3
4
5
6
@Test
public void filter_test() {
    Flux.range(1, 10)
            .filter(i -> i % 2 == 0)
            .subscribe(System.out::println);
}

4.2 transform 操作

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
// 不是 orange 的单词变成大写
@Test
public void advancedCompose() {
    Function<Flux<String>, Flux<String>> filterAndMap =
            f -> f.filter(color -> !color.equals("orange"))
                    .map(String::toUpperCase);

    Flux.fromIterable(Arrays.asList("blue", "green", "orange", "purple"))
            .doOnNext(System.out::println)
            .transform(filterAndMap)
            .subscribe(d -> System.out.println("Subscriber to Transformed MapAndFilter: " + d));
}

4.3 compose 与 transformDeferred 操作

comments powered by Disqus