Upgrade to the latest Reactor & SF
Related to https://github.com/spring-projects/spring-framework/issues/25884 * Don't use `MonoProcessor` & `FluxProcessor` since they are deprecated now * Fix RSocket components to use an `AtomicReference` header instead of deprecated `MonoProcessor` * Introduce an internal `IntegrationRSocketPayloadReturnValueHandler` to handle properly a Spring Integration case for inbound requests with its `IntegrationRSocketEndpoint` implementation * Don't do response handling in the `RSocketInboundGateway` any more since it is deferred now to the `IntegrationRSocketPayloadReturnValueHandler` * Remove internal `ChannelSendOperator` since it is out of use from now on
This commit is contained in:
@@ -29,7 +29,6 @@ import org.springframework.util.Assert;
|
||||
import reactor.core.Disposable;
|
||||
import reactor.core.Disposables;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.FluxProcessor;
|
||||
import reactor.core.publisher.Sinks;
|
||||
import reactor.core.scheduler.Schedulers;
|
||||
|
||||
@@ -46,9 +45,7 @@ import reactor.core.scheduler.Schedulers;
|
||||
public class FluxMessageChannel extends AbstractMessageChannel
|
||||
implements Publisher<Message<?>>, ReactiveStreamsSubscribableChannel {
|
||||
|
||||
private final Sinks.Many<Message<?>> sink;
|
||||
|
||||
private final FluxProcessor<Message<?>, Message<?>> processor;
|
||||
private final Sinks.Many<Message<?>> sink = Sinks.many().multicast().onBackpressureBuffer(1, false);
|
||||
|
||||
private final Sinks.Many<Boolean> subscribedSignal = Sinks.many().replay().limit(1);
|
||||
|
||||
@@ -56,14 +53,9 @@ public class FluxMessageChannel extends AbstractMessageChannel
|
||||
|
||||
private volatile boolean active = true;
|
||||
|
||||
public FluxMessageChannel() {
|
||||
this.sink = Sinks.many().multicast().onBackpressureBuffer(1, false);
|
||||
this.processor = FluxProcessor.fromSink(this.sink);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean doSend(Message<?> message, long timeout) {
|
||||
Assert.state(this.active && this.processor.hasDownstreams(),
|
||||
Assert.state(this.active && this.sink.currentSubscriberCount() > 0,
|
||||
() -> "The [" + this + "] doesn't have subscribers to accept messages");
|
||||
long remainingTime = 0;
|
||||
if (timeout > 0) {
|
||||
@@ -101,11 +93,12 @@ public class FluxMessageChannel extends AbstractMessageChannel
|
||||
|
||||
@Override
|
||||
public void subscribe(Subscriber<? super Message<?>> subscriber) {
|
||||
this.processor
|
||||
.doFinally((s) -> this.subscribedSignal.tryEmitNext(this.processor.hasDownstreams()))
|
||||
this.sink.asFlux()
|
||||
.doFinally((s) -> this.subscribedSignal.tryEmitNext(this.sink.currentSubscriberCount() > 0))
|
||||
.share()
|
||||
.subscribe(subscriber);
|
||||
this.subscribedSignal.tryEmitNext(this.processor.hasDownstreams());
|
||||
|
||||
this.subscribedSignal.tryEmitNext(this.sink.currentSubscriberCount() > 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -131,9 +124,9 @@ public class FluxMessageChannel extends AbstractMessageChannel
|
||||
@Override
|
||||
public void destroy() {
|
||||
this.active = false;
|
||||
this.subscribedSignal.tryEmitNext(false);
|
||||
this.upstreamSubscriptions.dispose();
|
||||
this.processor.onComplete();
|
||||
this.subscribedSignal.emitComplete(Sinks.EmitFailureHandler.FAIL_FAST);
|
||||
this.sink.emitComplete(Sinks.EmitFailureHandler.FAIL_FAST);
|
||||
super.destroy();
|
||||
}
|
||||
|
||||
|
||||
@@ -67,7 +67,6 @@ import org.springframework.messaging.support.MessageBuilder;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import reactor.core.publisher.Mono;
|
||||
import reactor.core.publisher.MonoProcessor;
|
||||
import reactor.core.publisher.Sinks;
|
||||
|
||||
/**
|
||||
@@ -899,7 +898,10 @@ public abstract class MessagingGatewaySupport extends AbstractEndpoint
|
||||
|
||||
@Override
|
||||
public void subscribeTo(Publisher<? extends Message<?>> publisher) {
|
||||
publisher.subscribe(MonoProcessor.fromSink(this.replyMono));
|
||||
Mono.from(publisher)
|
||||
.subscribe(
|
||||
(value) -> this.replyMono.emitValue(value, Sinks.EmitFailureHandler.FAIL_FAST),
|
||||
this.replyMono::tryEmitError, this.replyMono::tryEmitEmpty);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -51,7 +51,6 @@ import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
|
||||
|
||||
import reactor.core.Disposable;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.FluxProcessor;
|
||||
|
||||
/**
|
||||
* @author Artem Bilan
|
||||
@@ -141,7 +140,7 @@ public class FluxMessageChannelTests {
|
||||
|
||||
flowRegistration.destroy();
|
||||
|
||||
assertThat(TestUtils.getPropertyValue(flux, "processor", FluxProcessor.class).isTerminated()).isTrue();
|
||||
assertThat(TestUtils.getPropertyValue(flux, "sink.sink.done", Boolean.class)).isTrue();
|
||||
}
|
||||
|
||||
@Configuration
|
||||
|
||||
Reference in New Issue
Block a user