Reactor系列(二)Flux Mono建立

Flux Mono建立java

視頻講解:https://www.bilibili.com/video/av78844777/

FluxMonoTestCase.javareact

package com.example.reactor;

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

import java.time.Duration;
import java.util.Arrays;
import java.util.List;

@Slf4j
public class FluxMonoTestCase extends BaseTestCase {
    @Test
    public void createFlux() throws InterruptedException {
        //整型
        Flux<Integer> integerFlux = Flux.just(1, 2, 3, 4, 5);
        //字符串
        Flux<String> stringFlux = Flux.just("hello", "world");
        List<String> list = Arrays.asList("hello", "world");
        //列表
        Flux<String> stringFlux1 = Flux.fromIterable(list);
        //範圍
        Flux<Integer> integerFlux1 = Flux.range(1, 5);
        //時間間隔
        Flux<Long> longFlux = Flux.interval(Duration.ofMillis(1000));
        longFlux.subscribe(System.out::println);

        //Flux 建立
        Flux<String> stringFlux2 = Flux.from(stringFlux1);
        stringFlux2.subscribe(System.out::println);
        Thread.sleep(Long.MAX_VALUE);
    }
}

關注公衆號,堅持天天3分鐘視頻學習
api

相關文章
相關標籤/搜索