Reactor – Simple Ways to create Flux/Mono
reactor
2
Flux
3
Mono
2
Male avatar

loveprogramming viết ngày 03/05/2021

https://grokonez.com/reactive-programming/reactor/reactor-create-flux-and-mono-simple-ways-to-create-publishers-reactive-programming

Reactor – Simple Ways to create Flux/Mono

Reactive Streams is an API and pattern that provides a standard for asynchronous stream processing with non-blocking back pressure. It is also being introduced in Java 9 Flow API with four simple interfaces: Publisher, Subscriber, Subscription and Processor.

But Reactive Streams API is just low level to make practical use in reactive applications. So Reactor Core provides two main implementations of Publisher: Flux and Mono. In this tutorial, we're gonna know what they are and simple ways to create them.

I. Overview

For more details about Reactive Streams and Publish-Subscribe Pattern, please visit:
Java 9 Flow API – Reactive Streams

1. Flux & Mono

A Flux<T> is a standard Publisher<T> representing a reactive sequence of 0..N items, optionally terminated by either a success signal or an error.

While Mono<T> is a specialized Publisher<T> that emits at most single-valued-or-empty result.

2. Simple ways to create Publishers with Flux and Mono

2.1 Mono

  • Empty Mono:
    Mono<String> noData = Mono.empty();
    
  • Mono with value:
    Mono<String> data = Mono.just("JSA");
    
  • Mono that emits an Exception:
    
    Mono.error(new CustomException());
    

    2.2 Flux

  • Empty Flux:
    Flux<String> noData = Flux.empty();
  • Flux with items:
    Flux<String> data = Flux.just("Java", "Sample", "Approach", ".com");
  • Flux from Collections:

https://grokonez.com/reactive-programming/reactor/reactor-create-flux-and-mono-simple-ways-to-create-publishers-reactive-programming

Reactor – Simple Ways to create Flux/Mono

Bình luận


White
{{ comment.user.name }}
Bỏ hay Hay
{{comment.like_count}}
Male avatar
{{ comment_error }}
Hủy
   

Hiển thị thử

Chỉnh sửa

Male avatar

loveprogramming

451 bài viết.
79 người follow
Kipalog
{{userFollowed ? 'Following' : 'Follow'}}
Cùng một tác giả
Male avatar
1 0
Tutorial Link: (Link) (Ảnh) Django is a Pythonbased free and opensource web framework that follows the modeltemplateview architectural pattern. A...
loveprogramming viết 6 tháng trước
1 0
Male avatar
1 0
https://loizenai.com/angular11nodejspostgresqlcrudexample/ Angular 11 Node.js PostgreSQL Crud Example (Ảnh) Tutorial: “Angular 11 Node.js Postg...
loveprogramming viết 5 tháng trước
1 0
Male avatar
1 0
Angular Spring Boot jwt Authentication Example Github https://loizenai.com/angularspringbootjwt/ (Ảnh) Tutorial: ” Angular Spring Boot jwt Authe...
loveprogramming viết 5 tháng trước
1 0
Bài viết liên quan
Male avatar
0 0
https://grokonez.com/reactiveprogramming/reactor/reactorhowtocombinefluxmonoreactiveprogramming Reactor – How to Combine Publishers (Flux/Mono) I...
loveprogramming viết 24 ngày trước
0 0
{{like_count}}

kipalog

{{ comment_count }}

bình luận

{{liked ? "Đã kipalog" : "Kipalog"}}


Male avatar
{{userFollowed ? 'Following' : 'Follow'}}
451 bài viết.
79 người follow

 Đầu mục bài viết

Vẫn còn nữa! x

Kipalog vẫn còn rất nhiều bài viết hay và chủ đề thú vị chờ bạn khám phá!