#java#reactor#flux#zip#

压缩

视频讲解: https://www.bilibili.com/video/av80703840/

Reactor系列(十三)zipWith压缩

FluxMonoTestCase.java
package com.example.reactor;

import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;
import reactor.core.publisher.Flux;
import reactor.util.function.Tuple3;

@Slf4j
public class FluxMonoTestCase extends BaseTestCase {
    @Test
    public void zip(){
        Flux<String> stringFlux1 = Flux.just("a","b","c","d","e");
        Flux<String> stringFlux2 = Flux.just("f","g","h","i");
        Flux<String> stringFlux3 = Flux.just("1","2","3","4");
        //方法一zipWith
        stringFlux1.zipWith(stringFlux2).subscribe(x -> log.info("->{}",x));
        System.out.println();
        //方法二zip
        Flux<Tuple3<String,String,String>> tuple2Flux = Flux.zip(stringFlux1,stringFlux2,stringFlux3);
        tuple2Flux.subscribe(x -> log.info("->{}",x));
    }
}

结果:

11:28:47.027 [main] INFO com.example.reactor.FluxMonoTestCase - ->[a,f]
11:28:47.028 [main] INFO com.example.reactor.FluxMonoTestCase - ->[b,g]
11:28:47.028 [main] INFO com.example.reactor.FluxMonoTestCase - ->[c,h]
11:28:47.028 [main] INFO com.example.reactor.FluxMonoTestCase - ->[d,i]

11:28:47.029 [main] INFO com.example.reactor.FluxMonoTestCase - ->[a,f,1]
11:28:47.029 [main] INFO com.example.reactor.FluxMonoTestCase - ->[b,g,2]
11:28:47.029 [main] INFO com.example.reactor.FluxMonoTestCase - ->[c,h,3]
11:28:47.029 [main] INFO com.example.reactor.FluxMonoTestCase - ->[d,i,4]

相关文章:

  • 2022-12-23
  • 2021-09-16
  • 2021-11-27
  • 2022-12-23
  • 2021-10-03
  • 2021-09-17
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-02-11
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案