Reactor

翻车!Spring Boot 2.2.3 不兼容 Spring Cloud Hoxton.SR1

本小妞迷上赌 提交于 2020-02-26 00:50:58
问题说明 Spring Boot 2.2.3 修复了 Spring Boot 2.2 的大量问题,当升级至 2.2.3 以后,直接翻车 pigx-gateway 网关应用直接启动不起来。 翻车日志 *************************** APPLICATION FAILED TO START *************************** Description: An attempt was made to call a method that does not exist. The attempt was made from the following location: org.springframework.cloud.gateway.config.GatewayAutoConfiguration$NettyConfiguration.gatewayHttpClient(GatewayAutoConfiguration.java:597) The following method did not exist: reactor.netty.resources.ConnectionProvider.elastic(Ljava/lang/String;Ljava/time/Duration;)Lreactor/netty/resources

WebFlux系列(十二)MongoDB应用,新增、修改、查询、删除

懵懂的女人 提交于 2020-02-26 00:43:50
#Java#Spring#SpringBoot#Mongo#reactor#webflux#数据库#新增#修改#查询#删除# Spring Boot WebFlux Mongo数据库新增、删除、查询、修改 视频讲解 : https://www.bilibili.com/video/av84240038/ Employee.java package com.example.spring.webfluxmongo; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; import org.springframework.data.annotation.Id; import org.springframework.data.mongodb.core.mapping.Document; @Document @Data @AllArgsConstructor @NoArgsConstructor public class Employee { @Id private String id; private String name; } EmployeeController.java package com.example.spring.webfluxmongo;

Mock services in Spring Reactor

蹲街弑〆低调 提交于 2020-01-16 08:07:28
问题 Let's take a look over this simple method: public Mono<SuccessResponse> doSomething(){ return service1.doSomething() .then(service2.doSomething2()) .thenReturn(new SuccessResponse("Awesome"))); } So basically I want to test this method for a scenario in which, service1.doSomething() will throw an error: when(service1.doSomething()).thenReturn(Mono.error(new IllegalStateException("Something bad happened"))); when(service2.doSomething()).thenReturn(Mono.just(new SomeResponse()))

Mock services in Spring Reactor

霸气de小男生 提交于 2020-01-16 08:07:11
问题 Let's take a look over this simple method: public Mono<SuccessResponse> doSomething(){ return service1.doSomething() .then(service2.doSomething2()) .thenReturn(new SuccessResponse("Awesome"))); } So basically I want to test this method for a scenario in which, service1.doSomething() will throw an error: when(service1.doSomething()).thenReturn(Mono.error(new IllegalStateException("Something bad happened"))); when(service2.doSomething()).thenReturn(Mono.just(new SomeResponse()))

Mock services in Spring Reactor

爷,独闯天下 提交于 2020-01-16 08:07:05
问题 Let's take a look over this simple method: public Mono<SuccessResponse> doSomething(){ return service1.doSomething() .then(service2.doSomething2()) .thenReturn(new SuccessResponse("Awesome"))); } So basically I want to test this method for a scenario in which, service1.doSomething() will throw an error: when(service1.doSomething()).thenReturn(Mono.error(new IllegalStateException("Something bad happened"))); when(service2.doSomething()).thenReturn(Mono.just(new SomeResponse()))

Is twisted.internet.reactor global?

萝らか妹 提交于 2020-01-14 07:56:07
问题 For example, if one application does from twisted.internet import reactor , and another application does the same, are those reactors the same? I am asking because Deluge, an application that uses twisted, looks like it uses the reactor to connect their UI (gtk) to the rest of the application being driven by twisted (I am trying to understand the source). For example, when the UI is closed it simply calls reactor.stop() . Is that all there is to it? It just seems kind of magic to me. What if

Project reactor: collectList() doesn't work for Flux.create()

岁酱吖の 提交于 2020-01-11 11:34:54
问题 Below example prints integers from 1 to 10 and a list of (7, 8, 9, 10) public void streamCollect() { ConnectableFlux<Integer> connect = Flux.range(1, 10) .publish(); connect.subscribe(v -> System.out.println("1: " + v)); connect .filter(number -> number > 6) .collectList() .subscribe(v -> System.out.println("4: " + v)); connect.connect(); } Result: 1: 1 1: 2 1: 3 1: 4 1: 5 1: 6 1: 7 1: 8 1: 9 1: 10 4: [7, 8, 9, 10] Next example should produce the same result but instead prints out only

WebFlux系列(五)WebClient基本应用

℡╲_俬逩灬. 提交于 2020-01-08 12:42:09
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> #Java#Spring#WebFlux#WebClient#Reactor# WebClient如何调用远程接口 视频讲解: https://www.bilibili.com/video/av82532764/ WebfluxServerApplication.java package com.example.webfluxserver; import lombok.extern.log4j.Log4j2; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.http.MediaType; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; import reactor.core.publisher.Flux; import java.time.Duration; @Log4j2

Reactor系列(十七)parallel多线程

五迷三道 提交于 2020-01-07 03:57:07
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> #java#reactor#flux#parallet# 多线程 视频解说: https://www.bilibili.com/video/av81386202/ FluxMonoTestCase.java package com.example.reactor; import lombok.extern.slf4j.Slf4j; import org.junit.jupiter.api.Test; import reactor.core.publisher.Flux; import reactor.core.scheduler.Schedulers; @Slf4j public class FluxMonoTestCase extends BaseTestCase { @Test public void parllel() throws InterruptedException { Flux.range(1,10) .parallel() .runOn(Schedulers.parallel()) .subscribe(x ->log.info("->{}",x)); } } 结果: 11:03:33.472 [main] DEBUG reactor.util.Loggers$LoggerFactory -

Reactor深度探索

时光毁灭记忆、已成空白 提交于 2020-01-07 03:51:39
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 技术点 反应器模式(Reactor) 同步非阻塞,每个事情可以分为几个步骤,每个步骤可以相应去做,每个步骤是不会相互影响的,但是做起来是串行的。有关Netty的具体实现,可以参考 Netty整理 Proactor模式 异步非阻塞,每个事情同时做,或者说是异步的去做, 观察者模式(Observer) JDK的实现可以参考 使用JDK的观察者接口进行消息推送 观察者模式是一个推的模式 迭代器模式(Iterator) 是一种拉的模式,数据准备好后,进行一个循环拉取。 Java并发模型 Reactive Reactive是一种编程方式,由不同的方式来实现 RxJava : Reactive Extensions Reactor : Spring WebFlux Reactive类库 Flow API : Java 9 Flow API实现 阻塞的弊端和并行的复杂 在Reactor官方的网站上,指出了现有编程的一些不足 https://projectreactor.io/docs/core/release/reference/index.html#_blocking_can_be_wasteful Reactor认为阻塞可能是浪费的 归纳 阻塞导致性能瓶颈和浪费资源 增加线程可能会引起资源竞争和并发问题(可见性问题