将io.projectreactor版本从2.0.x升级到3.0.4 - 使用Spring框架

时间:2017-01-17 22:31:20

标签: java spring rx-java reactive-programming project-reactor

我在尝试升级时遇到了问题。

目前我正在使用版本2.0.x,特别是 -

reactor.bus
reactor.rx.Stream
reactor.rx.Streams
reactor.core.processor.RingBufferProcessor
reactor.fn.Consumer

我正在使用maven,而且我对'projectreactor'有一个依赖 -

<groupId>io.projectreactor.spring</groupId>
<artifactId>reactor-spring-core</artifactId>

升级到3.0.4.RELEASE版本时,为了继续使用之前使用的所有内容,我需要显式导入 -

<groupId>io.projectreactor</groupId>
<artifactId>reactor-bus</artifactId>

<groupId>io.projectreactor</groupId>
<artifactId>reactor-stream</artifactId>

但我仍然缺席

reactor.core.processor.RingBufferProcessor
reactor.fn.Consumer

我不知道该怎么做。

2 个答案:

答案 0 :(得分:1)

reactor.fn.Consumer已替换为Java 8 java.util.function.Consumer

对于RingBufferProcessor,您必须使用环形缓冲区选择new processors之一。

Dispatcher现在是Schedulers,它们使用了Java的Executor

答案 1 :(得分:1)

reactor.rx.Stream -> reactor.core.publisher.Flux
reactor.rx.Streams -> reactor.core.publisher.Flux
reactor.rx.Promise -> reactor.core.publisher.Mono and reactor.core.publisher.MonoProcessor
reactor.core.processor.RingBufferProcessor -> reactor.core.publisher.TopicProcessor
reactor.fn.Consumer -> java.until.function.Consumer (Java 8)

没有新的弹簧模块,因为春季5直接包括这些新型的Reactor支持。

至于反应堆巴士: 根据设计,现在所有流路由(Flux / Mono链)都是键入的,因此动态路由不是我们功能的一部分。仍然有类型的替代方法,例如:

ReplayProcessor<MyEvent> rp = ReplayProcessor.create();
Flux<MyEvent> interest1 = rp.filter(ev -> filterInterest1(ev));
Flux<MyEvent> interest2 = rp.filter(ev -> filterInterest2(ev));
Flux<MyEvent> interest1_2 = rp.filter(ev -> filterInterest1(ev) || filterInterest2(ev));

interest1.subscribe(doSomethingForInterest1);
interest2.subscribe(doSomethingForInterest2);
interest1_2.subscribe(doSomethingForInterest1_2);

rp.onNext(new MyEvent("interest1")); //subscriber 1 and 3 react
rp.onNext(new MyEvent("interest1")); //subscriber 1 and 3 react
rp.onNext(new MyEvent("interest2")); //subscriber 2 and 3 react
rp.onNext(new MyEvent("interest4")); // buffered until interest subscriber because ReplayProcessor

//shutdown/cleanup/close
rp.onComplete();

我在github上发现了这个似乎符合你的需求