美文网首页
spring中的反应式编程

spring中的反应式编程

作者: 风一样的存在 | 来源:发表于2021-07-19 09:25 被阅读0次

在看了spring-cloud-gateway部分代码后,发现很多地方用到了反应式编程,Mono和Flux到处可见。反应式本质上类似于发布订阅,事件驱动,类似的有epoll

//可以多次发射
Flux.create(t->{
    t.next("hello");
    t.next("world");
    t.complete();
}).subscribe(System.out::println);

//只能调用一次next
Flux.generate(t->{
    t.next("peter");
    t.complete();
}).subscribe(System.out::println);

Flux.just("1","2","3","4","5").subscribe(System.out::println);

Flux.from(Flux.just("1","2","3","4","5")).subscribe(System.out::println);

Flux.fromIterable(Lists.newArrayList("1", "2", "3", "4", "5")).subscribe(System.out::println);

Flux.fromStream(Stream.of("1", "2", "3", "4", "5")).subscribe(System.out::println);

Flux.fromArray(new String[]{"1", "2", "3", "4", "5"}).subscribe(System.out::println);

Flux.defer(()-> Flux.just("peter","jack","bob")).subscribe(System.out::println);

//不发射任何东西
Flux.empty().subscribe(System.out::println);

Flux.range(0,10).subscribe(System.out::println);

Flux.never().subscribe(System.out::println);

//创建一个Flux,它在订阅之后立即以指定的错误终止
Flux.error(new RuntimeException("运行错误")).subscribe(System.out::println);

//合并[a,c][b,d]
Flux.just("a", "b")
        .zipWith(Flux.just("c", "d"))
        .subscribe(System.out::println);

//合并a,b,c,d
Flux.just("a", "b")
        .mergeWith(Flux.just("c", "d"))
        .subscribe(System.out::println);

相关文章

  • Reactor: webflux 导入导出功能

    spring从指令式编程跨度到反应式编程(Reactive programming),这时我们怎么实现导入导出功能...

  • 总览:java8到webflux

    (从函数式编程到反应式编程) 反应式编程中,流是基础,并且反应式编程解决之前异步调用的问题,java8引入了流和新...

  • spring中的反应式编程

    在看了spring-cloud-gateway部分代码后,发现很多地方用到了反应式编程,Mono和Flux到处可见...

  • 反应式编程-流处理

    反应式编程 反应式编程的风格:非阻塞,异步,函数式 The Reactive Manifesto 反应式编程应有的...

  • SpringBoot(七、sse,响应式编程)

    Webflux 1、Spring WebFlux是Spring Framework 5.0中引入的新的反应式Web...

  • webflux的delay原理详解

    反应式编程一开始是从前端和客户端开始兴起,现在大有蔓延到后端的趋势,Spring5推出的webflux就是反应式编...

  • spring-webflux简介与示例

    简介 Spring WebFlux是Spring Framework 5.0中引入的新的反应式Web框架。与Spr...

  • spring-webflux简介与示例

    简介 Spring WebFlux是Spring Framework 5.0中引入的新的反应式Web框架。与Spr...

  • 深入剖析 Spring WebFlux

    一、WebFlux 简介 WebFlux 是 Spring Framework5.0 中引入的一种新的反应式Web...

  • 3、 reactor

    Reactor 简介 前面提到的 RxJava 库是 JVM 上反应式编程的先驱,也是反应式流规范的基础。RxJa...

网友评论

      本文标题:spring中的反应式编程

      本文链接:https://www.haomeiwen.com/subject/eodcmltx.html