Reactor

How to limit the number of active Spring WebClient calls

試著忘記壹切 提交于 2019-12-22 09:45:57
问题 I have a requirement where I read a bunch of rows (thousands) from a SQL DB using Spring Batch and call a REST Service to enrich content before writing them on a Kafka topic. When using the Spring Reactive webClient, how do I limit the number of active non-blocking service calls? Should I somehow introduce a Flux in the loop after I read data using Spring Batch? (I understand the usage of delayElements and that it serves a different purpose, as when a single Get Service Call brings in lot of

Reactor系列(十)collectMap集合

ぃ、小莉子 提交于 2019-12-21 12:32:02
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> #java#reactor#collect#hashMap# 转换成Map 视频讲解: https://www.bilibili.com/video/av80048104/ 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.publisher.Mono; import java.util.Map; @Slf4j public class FluxMonoTestCase extends BaseTestCase { @Test public void collectMap(){ Flux<Employee> employeeFlux = Flux.fromIterable(list); //转换HashMap Mono<Map<String,Employee>> mono = employeeFlux .collectMap(key ->key.getName(),val ->val); mono

Will Reactor provide remoting?

99封情书 提交于 2019-12-19 08:16:11
问题 I'm trying to find out whether we should use Akka or Reactor for our next project. One of the most important questions is if the future framework of choice will provide remoting. As i saw, Akka offers this just in the way we'd like to have it. In the GitHub wiki, unfortunately the TCP-server/client sections are blank and i couldn't find other informations about that yet. Will reactor provide remoting? 回答1: I don't think Akka and Reactor are Apples to Apples. Reactor is purposely minimal, with

Reactor系列(八)concatMap有序映射

荒凉一梦 提交于 2019-12-18 13:52:29
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> #java#reactor#comcatMap# 有序映射 视频讲解: https://www.bilibili.com/video/av79705356/ FluxMonoTestCase.java package com.example.reactor; import lombok.extern.slf4j.Slf4j; import org.junit.jupiter.api.Test; import reactor.core.publisher.Flux; import java.time.Duration; @Slf4j public class FluxMonoTestCase extends BaseTestCase { @Test public void concatMap() throws InterruptedException { Flux<String> stringFlux1 = Flux.just("a","b","c","d","e","f","g","h","i"); Flux<Flux<String>> stringFlux2 = stringFlux1.window(2); stringFlux2.concatMap(flux1 ->flux1.map(word ->word

Reactor系列(七)flatMap映射

陌路散爱 提交于 2019-12-17 11:49:24
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> #java##reactor##flatMap# 视频讲解: https://www.bilibili.com/video/av79582009/ FluxMonoTestCase.java package com.example.reactor; import lombok.extern.slf4j.Slf4j; import org.junit.jupiter.api.Test; import reactor.core.publisher.Flux; @Slf4j public class FluxMonoTestCase extends BaseTestCase { @Test public void flatMap(){ Flux<String> stringFlux1 = Flux.just("a","b","c","d","e","f","g","h","i"); //嵌套Flux Flux<Flux<String>> stringFlux2 = stringFlux1.window(2); stringFlux2.flatMap(flux1 ->flux1.map(word ->word.toUpperCase())) .subscribe(System.out::println); /

How to set a timeout in Spring 5 WebFlux WebClient

倖福魔咒の 提交于 2019-12-17 10:48:12
问题 I'm trying to set timeout on my WebClient, here is the current code : SslContext sslContext = SslContextBuilder.forClient().trustManager(InsecureTrustManagerFactory.INSTANCE).build(); ClientHttpConnector httpConnector = new ReactorClientHttpConnector(opt -> { opt.sslContext(sslContext); HttpClientOptions option = HttpClientOptions.builder().build(); opt.from(option); }); return WebClient.builder().clientConnector(httpConnector).defaultHeader("Authorization", xxxx) .baseUrl(this.opusConfig

Reactor系列(六)Exception异常系列(六)Exception异常

我只是一个虾纸丫 提交于 2019-12-16 13:12:52
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> #java##reactor##flux##error##exception# 视频解说: https://www.bilibili.com/video/av79468713/ FluxMonoTestCase.java package com.example.reactor; import lombok.extern.slf4j.Slf4j; import org.junit.jupiter.api.Test; import reactor.core.publisher.Flux; import java.io.IOException; @Slf4j public class FluxMonoTestCase extends BaseTestCase { @Test public void error() { Flux.range(-2, 5) .map(val -> { int i = val / val; return val; }) .onErrorContinue((ex, val) -> { //遇到错误继续订阅 if (ex instanceof IOException) { log.error("ex:{},val:{}", ex, val); } else { } })

对Netty的一些理解

别来无恙 提交于 2019-12-14 22:15:55
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> Netty 是一个高性能、异步事件驱动的 NIO 框架,它提供了对 TCP 、 UDP 和文件传输的支持。作为当前最流行的 NIO 框架, Netty 在互联网领域、大数据分布式计算领域、游戏行业、通信行业等获得了广泛的应用,一些业界著名的开源组件也是基于 Netty 的 NIO 框架构建。 Netty 利用 Java 高级网络的能力,隐藏其背后的复杂性而提供一个易于使用的 API 构建一个客户端/服务端,其具有高并发、传输快、封装好等特点。 高并发 Netty 是一款基于 NIO ( Nonblocking I/O ,非阻塞 IO )开发的网络通信框架,对比于 BIO ( Blocking I/O ,阻塞 IO ),它的并发性能得到了很大提高 。 传输快 Netty 的传输快其实也是依赖了 NIO 的一个特性—— 零拷贝 。 封装好 Netty封装了NIO操作的很多细节,提供易于使用的API,还有心跳、重连机制、拆包粘包方案等特性,使开发者能能够快速高效的构建一个稳健的高并发应用。 为什么要用 Netty ? JDK 原生 NIO 程序的问题 JDK 原生也有一套网络应用程序 API ,但是存在一系列问题,主要如下: NIO 的类库和 API 繁杂,使用麻烦。你需要熟练掌握 Selector 、

聊聊FluxFlatMap的concurrency及prefetch参数

大城市里の小女人 提交于 2019-12-14 17:00:41
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 序 本文主要研究下FluxFlatMap的concurrency及prefetch参数 实例 @Test public void testConcurrencyAndPrefetch(){ int concurrency = 3; int prefetch = 6; Flux.range(1,100) .log() .flatMap(i -> Flux.just(1,2,3,4,5,6,7,8,9,10).log(), concurrency,prefetch) .subscribe(); } 部分输出 23:29:38.515 [main] DEBUG reactor.util.Loggers$LoggerFactory - Using Slf4j logging framework 23:29:38.534 [main] INFO reactor.Flux.Range.1 - | onSubscribe([Synchronous Fuseable] FluxRange.RangeSubscription) 23:29:38.537 [main] INFO reactor.Flux.Range.1 - | request(3) 23:29:38.537 [main] INFO reactor.Flux

reactor-kafka小试牛刀

假如想象 提交于 2019-12-14 16:54:08
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 序 本文主要展示一下如何使用reactor-kafka maven <dependency> <groupId>io.projectreactor.kafka</groupId> <artifactId>reactor-kafka</artifactId> <version>1.0.1.RELEASE</version> </dependency> 准备 启动zookeeper cd zookeeper-3.4.13 sh bin/zkServer.sh start ZooKeeper JMX enabled by default ZooKeeper remote JMX Port set to 8999 ZooKeeper remote JMX authenticate set to false ZooKeeper remote JMX ssl set to false ZooKeeper remote JMX log4j set to true Using config: zookeeper-3.4.13/bin/../conf/zoo.cfg -n Starting zookeeper ... STARTED 启动kafka cd kafka_2.11-1.1.1 sh bin/kafka-server