Fix deprecations from Reactor
This commit is contained in:
@@ -24,10 +24,11 @@ import org.springframework.util.Assert;
|
||||
|
||||
import reactor.core.Disposable;
|
||||
import reactor.core.Disposables;
|
||||
import reactor.core.publisher.EmitterProcessor;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.FluxIdentityProcessor;
|
||||
import reactor.core.publisher.FluxSink;
|
||||
import reactor.core.publisher.ReplayProcessor;
|
||||
import reactor.core.publisher.Processors;
|
||||
import reactor.core.publisher.Sinks;
|
||||
import reactor.core.scheduler.Schedulers;
|
||||
|
||||
/**
|
||||
@@ -43,16 +44,17 @@ import reactor.core.scheduler.Schedulers;
|
||||
public class FluxMessageChannel extends AbstractMessageChannel
|
||||
implements Publisher<Message<?>>, ReactiveStreamsSubscribableChannel {
|
||||
|
||||
private final EmitterProcessor<Message<?>> processor;
|
||||
private final FluxIdentityProcessor<Message<?>> processor;
|
||||
|
||||
private final FluxSink<Message<?>> sink;
|
||||
|
||||
private final ReplayProcessor<Boolean> subscribedSignal = ReplayProcessor.create(1);
|
||||
private final Sinks.StandaloneFluxSink<Boolean> subscribedSignal = Sinks.replay(1);
|
||||
|
||||
private final Disposable.Composite upstreamSubscriptions = Disposables.composite();
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public FluxMessageChannel() {
|
||||
this.processor = EmitterProcessor.create(1, false);
|
||||
this.processor = Processors.more().multicast(1, false);
|
||||
this.sink = this.processor.sink(FluxSink.OverflowStrategy.BUFFER);
|
||||
}
|
||||
|
||||
@@ -67,16 +69,16 @@ public class FluxMessageChannel extends AbstractMessageChannel
|
||||
@Override
|
||||
public void subscribe(Subscriber<? super Message<?>> subscriber) {
|
||||
this.processor
|
||||
.doFinally((s) -> this.subscribedSignal.onNext(this.processor.hasDownstreams()))
|
||||
.doFinally((s) -> this.subscribedSignal.next(this.processor.hasDownstreams()))
|
||||
.subscribe(subscriber);
|
||||
this.subscribedSignal.onNext(this.processor.hasDownstreams());
|
||||
this.subscribedSignal.next(this.processor.hasDownstreams());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void subscribeTo(Publisher<? extends Message<?>> publisher) {
|
||||
this.upstreamSubscriptions.add(
|
||||
Flux.from(publisher)
|
||||
.delaySubscription(this.subscribedSignal.filter(Boolean::booleanValue).next())
|
||||
.delaySubscription(this.subscribedSignal.asFlux().filter(Boolean::booleanValue).next())
|
||||
.publishOn(Schedulers.boundedElastic())
|
||||
.doOnNext((message) -> {
|
||||
try {
|
||||
@@ -91,7 +93,7 @@ public class FluxMessageChannel extends AbstractMessageChannel
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
this.subscribedSignal.onNext(false);
|
||||
this.subscribedSignal.next(false);
|
||||
this.upstreamSubscriptions.dispose();
|
||||
this.processor.onComplete();
|
||||
super.destroy();
|
||||
|
||||
@@ -30,9 +30,10 @@ import org.springframework.messaging.MessagingException;
|
||||
import org.springframework.messaging.PollableChannel;
|
||||
import org.springframework.messaging.SubscribableChannel;
|
||||
|
||||
import reactor.core.publisher.EmitterProcessor;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.FluxIdentityProcessor;
|
||||
import reactor.core.publisher.Mono;
|
||||
import reactor.core.publisher.Processors;
|
||||
import reactor.core.scheduler.Schedulers;
|
||||
|
||||
/**
|
||||
@@ -101,7 +102,7 @@ public final class IntegrationReactiveUtils {
|
||||
* - a {@link org.springframework.integration.channel.FluxMessageChannel}
|
||||
* is returned as is because it is already a {@link Publisher};
|
||||
* - a {@link SubscribableChannel} is subscribed with a {@link MessageHandler}
|
||||
* for the {@link EmitterProcessor#onNext(Object)} which is returned from this method;
|
||||
* for the {@link FluxIdentityProcessor#onNext(Object)} which is returned from this method;
|
||||
* - a {@link PollableChannel} is wrapped into a {@link MessageSource} lambda and reuses
|
||||
* {@link #messageSourceToFlux(MessageSource)}.
|
||||
* @param messageChannel the {@link MessageChannel} to adapt.
|
||||
@@ -127,7 +128,7 @@ public final class IntegrationReactiveUtils {
|
||||
|
||||
private static <T> Flux<Message<T>> adaptSubscribableChannelToPublisher(SubscribableChannel inputChannel) {
|
||||
return Flux.defer(() -> {
|
||||
EmitterProcessor<Message<T>> publisher = EmitterProcessor.create(1);
|
||||
FluxIdentityProcessor<Message<T>> publisher = Processors.more().multicast(1);
|
||||
@SuppressWarnings("unchecked")
|
||||
MessageHandler messageHandler = (message) -> publisher.onNext((Message<T>) message);
|
||||
inputChannel.subscribe(messageHandler);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2016-2019 the original author or authors.
|
||||
* Copyright 2016-2020 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -50,8 +50,8 @@ import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
|
||||
|
||||
import reactor.core.Disposable;
|
||||
import reactor.core.publisher.EmitterProcessor;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.FluxIdentityProcessor;
|
||||
|
||||
/**
|
||||
* @author Artem Bilan
|
||||
@@ -141,7 +141,7 @@ public class FluxMessageChannelTests {
|
||||
|
||||
flowRegistration.destroy();
|
||||
|
||||
assertThat(TestUtils.getPropertyValue(flux, "processor", EmitterProcessor.class).isTerminated()).isTrue();
|
||||
assertThat(TestUtils.getPropertyValue(flux, "processor", FluxIdentityProcessor.class).isTerminated()).isTrue();
|
||||
}
|
||||
|
||||
@Configuration
|
||||
|
||||
@@ -57,9 +57,10 @@ import org.springframework.messaging.MessageHandler;
|
||||
import org.springframework.messaging.ReactiveMessageHandler;
|
||||
import org.springframework.messaging.support.GenericMessage;
|
||||
|
||||
import reactor.core.publisher.EmitterProcessor;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.FluxIdentityProcessor;
|
||||
import reactor.core.publisher.Mono;
|
||||
import reactor.core.publisher.Processors;
|
||||
import reactor.test.StepVerifier;
|
||||
import reactor.util.Loggers;
|
||||
|
||||
@@ -298,7 +299,7 @@ public class ReactiveStreamsConsumerTests {
|
||||
public void testReactiveStreamsConsumerFluxMessageChannelReactiveMessageHandler() {
|
||||
FluxMessageChannel testChannel = new FluxMessageChannel();
|
||||
|
||||
EmitterProcessor<Message<?>> processor = EmitterProcessor.create(2, false);
|
||||
FluxIdentityProcessor<Message<?>> processor = Processors.more().multicast(2, false);
|
||||
|
||||
ReactiveMessageHandler messageHandler =
|
||||
m -> {
|
||||
|
||||
@@ -84,7 +84,7 @@ import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
|
||||
|
||||
import reactor.core.publisher.Mono;
|
||||
import reactor.core.publisher.MonoProcessor;
|
||||
import reactor.core.publisher.Sinks;
|
||||
import reactor.test.StepVerifier;
|
||||
|
||||
/**
|
||||
@@ -241,7 +241,8 @@ public class MessagingAnnotationsWithBeanAnnotationTests {
|
||||
this.reactiveMessageHandlerChannel.send(new GenericMessage<>("test"));
|
||||
|
||||
StepVerifier.create(
|
||||
this.contextConfiguration.messageMonoProcessor
|
||||
this.contextConfiguration.messageMono
|
||||
.asMono()
|
||||
.map(Message::getPayload)
|
||||
.cast(String.class))
|
||||
.expectNext("test")
|
||||
@@ -291,7 +292,7 @@ public class MessagingAnnotationsWithBeanAnnotationTests {
|
||||
}
|
||||
|
||||
@Bean
|
||||
@Router(inputChannel = "routerChannel", channelMappings = { "true=odd", "false=filter" }, suffix = "Channel")
|
||||
@Router(inputChannel = "routerChannel", channelMappings = {"true=odd", "false=filter"}, suffix = "Channel")
|
||||
public MessageSelector router() {
|
||||
return new ExpressionEvaluatingSelector("payload % 2 == 0");
|
||||
}
|
||||
@@ -373,7 +374,8 @@ public class MessagingAnnotationsWithBeanAnnotationTests {
|
||||
@Filter(inputChannel = "skippedChannel5")
|
||||
@Profile("foo")
|
||||
public MessageHandler skippedMessageHandler() {
|
||||
return m -> { };
|
||||
return m -> {
|
||||
};
|
||||
}
|
||||
|
||||
@Bean
|
||||
@@ -427,7 +429,7 @@ public class MessagingAnnotationsWithBeanAnnotationTests {
|
||||
return collector()::add;
|
||||
}
|
||||
|
||||
MonoProcessor<Message<?>> messageMonoProcessor = MonoProcessor.create();
|
||||
Sinks.StandaloneMonoSink<Message<?>> messageMono = Sinks.promise();
|
||||
|
||||
@Bean
|
||||
MessageChannel reactiveMessageHandlerChannel() {
|
||||
@@ -438,8 +440,7 @@ public class MessagingAnnotationsWithBeanAnnotationTests {
|
||||
@ServiceActivator(inputChannel = "reactiveMessageHandlerChannel")
|
||||
public ReactiveMessageHandler reactiveMessageHandlerService() {
|
||||
return (message) -> {
|
||||
messageMonoProcessor.onNext(message);
|
||||
messageMonoProcessor.onComplete();
|
||||
messageMono.success(message);
|
||||
return Mono.empty();
|
||||
};
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@ import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
|
||||
|
||||
import reactor.core.publisher.Mono;
|
||||
import reactor.core.publisher.MonoProcessor;
|
||||
import reactor.core.publisher.Sinks;
|
||||
import reactor.test.StepVerifier;
|
||||
|
||||
/**
|
||||
@@ -88,14 +88,14 @@ public class GatewayParserTests {
|
||||
Message<?> result = channel.receive(10000);
|
||||
assertThat(result.getPayload()).isEqualTo("foo");
|
||||
|
||||
MonoProcessor<Object> defaultMethodHandler = MonoProcessor.create();
|
||||
Sinks.StandaloneMonoSink<Object> defaultMethodHandler = Sinks.promise();
|
||||
|
||||
this.errorChannel.subscribe(message -> defaultMethodHandler.onNext(message.getPayload()));
|
||||
this.errorChannel.subscribe(message -> defaultMethodHandler.success(message.getPayload()));
|
||||
|
||||
String defaultMethodPayload = "defaultMethodPayload";
|
||||
service.defaultMethodGateway(defaultMethodPayload);
|
||||
|
||||
StepVerifier.create(defaultMethodHandler)
|
||||
StepVerifier.create(defaultMethodHandler.asMono())
|
||||
.expectNext(defaultMethodPayload)
|
||||
.verifyComplete();
|
||||
}
|
||||
@@ -423,7 +423,7 @@ public class GatewayParserTests {
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
@SuppressWarnings({"rawtypes", "unchecked"})
|
||||
public <T> Future<T> submit(Callable<T> task) {
|
||||
try {
|
||||
Future<?> result = super.submit(task);
|
||||
|
||||
Reference in New Issue
Block a user