当前位置:网站首页>Création de mono
Création de mono
2022-06-21 23:58:00 【_ Bar _ Lrs】
Table des matières
Préface
Reactor Est basé sur JVM Bibliothèque de base d'application asynchrone au - dessus.Pour Java 、Groovy Et autres JVM Le langage fournit une bibliothèque abstraite pour construire des applications basées sur des événements et des données,Utilisez - le pour construire une application de données de flux efficace dans le temps,Rendre l'application efficace、Transmission asynchrone des messages.
Reactor Performance assez élevée,Sur la dernière plateforme matérielle,Il est possible de traiter toutes les secondes avec un distributeur sans blocage 1500 Événement Wan.
Reactor Deux concepts importants sontFlux Et Mono.Mono Indique que contient 0 Ou 1 Séquence asynchrone des éléments.Flux Indique que contient 0 À N Séquence asynchrone des éléments.Ils contiennent trois types différents de notifications de messages:Message normal contenant des éléments、Message de fin de séquence et message d'erreur de séquence.
Un.、Flux de données réactifs
Flux de données réactifs En tant que nouvelle spécification de flux de données pour Java 9 Et ses versions ultérieures,Conçu pour fournir les mêmes/Contrôle asynchrone du flux de données séquentielles.
1、Interface de flux de données réactive
org.reactivestreams.Pubslisher:Éditeur de flux de données(Signal de 0 À N,N Peut être infini).Deux événements terminaux optionnels sont disponibles:Erreurs et achèvement.
org.reactivestreams.Subscriber: Consommateurs de flux de données (Signal de 0 À N,N Peut être infini). Lors de l'initialisation du consommateur , Combien de données le producteur doit - il actuellement s'abonner? .Autres situations, Interagir avec le producteur de données par le biais d'un rappel d'interface : Article suivant(Nouvelles informations)Et l'état.Le statut comprend::Terminé./Erreur,Facultatif.
org.reactivestreams.Subscription: La phase d'initialisation passe un petit traceur à l'abonné . Il contrôle la quantité de données que nous sommes prêts à consommer. , Et quand nous voulons arrêter de consommer (Annulation).
org.reactivestreams.Processor: Étiquetage des composants en tant qu'éditeur et abonné .
2、 Protocole de diffusion en continu réactif
Les abonnés ont deux façons de demander des données à l'éditeur :
Illimité: Les abonnés n'ont qu'à appeler Subscription#request(Long.MAX_VALUE) C'est tout..
Borné: Les abonnés conservent les références de données ,Appelezrequest(long) Consommation méthodologique.
2.、MonoCréation de
(1)empty
Ne contient aucun élément, Peut publier un message de fin
@Test
public void empty(){
Mono.empty().subscribe(System.out::println);
}
(2)just
Contient l'élément spécifié
@Test
public void just(){
Mono.just("hello mono").subscribe(System.out::println);
}
(3)justOrEmpty
Lorsqu'il y a un élément just,
Équivalent sans élément empty,
L'élément estOptionalHeure,SelonOptional Y a - t - il des valeurs pour créer justOuempty.
@Test
public void justOrEmpty(){
Mono.justOrEmpty("hello mono").subscribe(System.out::println);
}
(4)never
Ne contient aucun élément
@Test
public void never(){
Mono.never().subscribe(System.out::println);
}
(5)from
@Test
public void from() {
//De Publisher Générer Mono
Mono.from(Mono.just("hello mono")).subscribe(System.out::println);
//De Publisher Générer Mono,Oui.FluxType à emballer
Mono.fromDirect(Mono.just("hello mono")).subscribe(System.out::println);
//De Supplier Générer Mono
Mono.fromSupplier(() -> "hello mono").subscribe(System.out::println);
//De Runnable Générer Mono
Mono.fromRunnable(() -> System.out.println("hello mono")).subscribe(System.out::println);
//De Callable Générer Mono
Mono.fromCallable(() ->"hello mono").subscribe(System.out::println);
//De CompletableFuture Générer Mono
Mono.fromFuture(CompletableFuture.completedFuture("hello mono")).subscribe(System.out::println);
//De CompletionStage Générer Mono
Mono.fromCompletionStage(CompletableFuture.completedFuture("hello mono")).subscribe(System.out::println);
//De Supplier<? extends CompletionStage<? extends T> Générer Mono
Mono.fromCompletionStage(() -> CompletableFuture.completedFuture("hello mono")).subscribe(System.out::println);
}
(6)defer
@Test
public void defer() {
//De Supplier Accès mono
Mono.defer(() -> Mono.just("hello mono")).subscribe(System.out::println);
//De Function<ContextView, ? extends Mono<? extends T>> Accès mono
Mono.deferContextual(view -> Mono.just("hello mono")).subscribe(System.out::println);
}
(7)delay
@Test
public void delay() throws InterruptedException {
// Spécifier le délai , La valeur de publication est 0
Mono.delay(Duration.of(5, ChronoUnit.SECONDS)).subscribe(System.out::println);
Mono.delay(Duration.of(5, ChronoUnit.SECONDS), Schedulers.parallel()).subscribe(System.out::println);
TimeUnit.SECONDS.sleep(15);
}
(8)error
@Test
public void error() throws InterruptedException {
//Contient une exception mono
Mono.error(new RuntimeException("Une erreur s'est produite")).subscribe(System.out::println);
//Supplier Fournir des exceptions mono
Mono.error(() -> new RuntimeException("Une erreur s'est produite")).subscribe(System.out::println);
}
(9)first
@Test
public void first() throws InterruptedException {
//Traiter le premier mono, Si la première annulation ,Traiter la deuxième...
Mono.firstWithSignal(Mono.empty(), Mono.just("mono hello")).subscribe(System.out::println);
Mono.firstWithValue(Mono.just("hello mono"), Mono.just("mono hello")).subscribe(System.out::println);
Mono.firstWithSignal(List.of(Mono.just("hello mono"), Mono.just("mono hello"))).subscribe(System.out::println);
Mono.firstWithValue(List.of(Mono.just("hello mono"), Mono.just("mono hello"))).subscribe(System.out::println);
}
(10)sequenceEqual
@Test
public void sequenceEqual() throws InterruptedException {
//Comparer deux mono C'est pareil.
Mono.sequenceEqual(Mono.just("hello mono"), Mono.just("hello mono")).subscribe(System.out::println);
Mono.sequenceEqual(Mono.just("hello mono"), Mono.just("hello mono"), Object::equals).subscribe(System.out::println);
Mono.sequenceEqual(Mono.just("hello mono"), Mono.just("hello mono"), Object::equals, 16).subscribe(System.out::println);
}
(11)using
@Test
public void using() throws InterruptedException {
//callableRetourmono,
//functionC'est exact.monoExécution des opérations
//consumerEffectuer des opérations de nettoyage
//eager PourtrueHeure,consumerInsubscribePrécédemment appelé
Mono.using(() -> Mono.just("hello mono"), Function.identity(), t -> System.out.println(t)).subscribe(System.out::println);
}
(12)when
@Test
public void when() throws InterruptedException {
// Effectuer des opérations prédéfinies
Mono.when(Mono.just("hello mono").filter(a -> a.equals("hello mono"))).subscribe(System.out::println);
}
(13)zip
Opération de compression
边栏推荐
- Inventory common vulnerability utilization methods
- Elementary transformation of numpy matrix
- JS listening and removing listening events
- Component value transfer: value transfer between siblings (value transfer by non parent and child components)
- IPD chip shipments exceeded 1billion, and chips and semiconductors appeared in ims2022
- About the solution to the "fatal error: gl/gl.h: no such file or directory" of Qilin system development error
- Hardware development notes (V): basic process of hardware development, making a USB to RS232 module (IV): creating con connection device package and associating principle element devices
- 麒麟系统开发笔记(五):制作安装麒麟系统的启动U盘、物理机安装麒麟系统以及搭建Qt开发环境
- golang调用sdl2,播放pcm音频,报错signal arrived during external code execution。
- Xiuno修罗轻论坛仿知乎蓝简约响应式主题模板1.7+自适应PC+WAP端
猜你喜欢

Cola and herbal tea speed up mutual rolling

树莓派开发笔记(十七):树莓派4B+上Qt多用户连接操作Mysql数据库同步(单条数据悲观锁)

标志位生成

211 thèse de maîtrise en divinité à l'Université! 75 lignes et 20 mauvaises lignes! Réponse de l'école: le tuteur a arrêté d'inscrire...

在线文本按行批量反转工具

Hardware development notes (V): basic process of hardware development, making a USB to RS232 module (IV): creating con connection device package and associating principle element devices
![[highly recommended] markdown grammar](/img/6c/df2ebb3e39d1e47b8dd74cfdddbb06.gif)
[highly recommended] markdown grammar

Nuxt SSR packaging and deployment

Here comes the CV overview of target detection, visual weakly supervised learning, brain multimodal imaging technology and so on! Image graphics development annual report review special issue!

QT document reading notes staticmetaobject parsing and instances
随机推荐
ERP is dead, the management background is cold, and seckill system is king!
[highly recommended] markdown grammar
组件传值:父组件与子组件传值用props
Go language learning tutorial (12)
Unity network development (II)
Promise error capture processing -- promise Technology
Based on vscode platformio under Arduino framework, one project is configured with two compatibility modes of different development boards
Hardware development notes (IV): basic process of hardware development, making a USB to RS232 module (III): design schematic diagram
spacy.load(“en_core_web_sm“)###OSError: [E050] Can‘t find model ‘en_core_web_sm‘.
外部排序的基本内容
Unity network development (I)
Solutions to the problem that Allegro's pcbeditor is often stuck or busy in use
QT practical skill: close unnecessary warning prompt on the right in the qtcreator editing area
Voir la valeur des données, éclairer l'avenir numérique, le pouvoir numérique est sorti
class path resource [classpath*:mapper/*.xml] cannot be opened because it does not exist
About the solution to "the application cannot start normally 0xc00000022" after qt5.15.2 is installed and qtcreator is started
Hardware development notes (V): basic process of hardware development, making a USB to RS232 module (IV): creating con connection device package and associating principle element devices
IPD芯片出货量超10亿颗,芯和半导体亮相IMS2022
关于 allegro的pcbEditor在使用过程中经常卡或者busy无响应 的解决方法
Truncate strings by length into an array