Switch to Reactor 2020.0.0 snapshots

A switch to RSocket 1.0.1 snapshots is also required to pick up a
for froward compatibility with Reactor Netty 1.0.

See gh-25085
This commit is contained in:
Rossen Stoyanchev
2020-05-29 15:07:07 +01:00
parent 42ff01b5aa
commit 6d6269f1ee
13 changed files with 84 additions and 45 deletions

View File

@@ -19,7 +19,6 @@ package org.springframework.messaging.tcp.reactor;
import java.time.Duration;
import java.util.Collection;
import java.util.List;
import java.util.Optional;
import java.util.function.BiFunction;
import java.util.function.Consumer;
import java.util.function.Function;
@@ -34,7 +33,6 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.reactivestreams.Publisher;
import reactor.core.publisher.DirectProcessor;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import reactor.core.publisher.MonoProcessor;
import reactor.core.scheduler.Scheduler;
@@ -46,6 +44,7 @@ import reactor.netty.NettyOutbound;
import reactor.netty.resources.ConnectionProvider;
import reactor.netty.resources.LoopResources;
import reactor.netty.tcp.TcpClient;
import reactor.util.retry.Retry;
import org.springframework.lang.Nullable;
import org.springframework.messaging.Message;
@@ -103,14 +102,13 @@ public class ReactorNettyTcpClient<P> implements TcpOperations<P> {
* @param codec for encoding and decoding the input/output byte streams
* @see org.springframework.messaging.simp.stomp.StompReactorNettyCodec
*/
@SuppressWarnings("deprecation")
public ReactorNettyTcpClient(String host, int port, ReactorNettyCodec<P> codec) {
Assert.notNull(host, "host is required");
Assert.notNull(codec, "ReactorNettyCodec is required");
this.channelGroup = new DefaultChannelGroup(ImmediateEventExecutor.INSTANCE);
this.loopResources = LoopResources.create("tcp-client-loop");
this.poolResources = ConnectionProvider.fixed("tcp-client-pool", 10000);
this.poolResources = ConnectionProvider.create("tcp-client-pool", 10000);
this.codec = codec;
this.tcpClient = TcpClient.create(this.poolResources)
@@ -129,13 +127,12 @@ public class ReactorNettyTcpClient<P> implements TcpOperations<P> {
* @since 5.1.3
* @see org.springframework.messaging.simp.stomp.StompReactorNettyCodec
*/
@SuppressWarnings("deprecation")
public ReactorNettyTcpClient(Function<TcpClient, TcpClient> clientConfigurer, ReactorNettyCodec<P> codec) {
Assert.notNull(codec, "ReactorNettyCodec is required");
this.channelGroup = new DefaultChannelGroup(ImmediateEventExecutor.INSTANCE);
this.loopResources = LoopResources.create("tcp-client-loop");
this.poolResources = ConnectionProvider.fixed("tcp-client-pool", 10000);
this.poolResources = ConnectionProvider.create("tcp-client-pool", 10000);
this.codec = codec;
this.tcpClient = clientConfigurer.apply(TcpClient
@@ -199,7 +196,6 @@ public class ReactorNettyTcpClient<P> implements TcpOperations<P> {
}
@Override
@SuppressWarnings("deprecation")
public ListenableFuture<Void> connect(TcpConnectionHandler<P> handler, ReconnectStrategy strategy) {
Assert.notNull(handler, "TcpConnectionHandler is required");
Assert.notNull(strategy, "ReconnectStrategy is required");
@@ -218,8 +214,12 @@ public class ReactorNettyTcpClient<P> implements TcpOperations<P> {
.doOnError(updateConnectMono(connectMono))
.doOnError(handler::afterConnectFailure) // report all connect failures to the handler
.flatMap(Connection::onDispose) // post-connect issues
.retryWhen(reconnectFunction(strategy))
.repeatWhen(reconnectFunction(strategy))
.retryWhen(Retry.from(signals -> signals
.map(retrySignal -> (int) retrySignal.totalRetriesInARow())
.flatMap(attempt -> reconnect(attempt, strategy))))
.repeatWhen(flux -> flux
.scan(1, (count, element) -> count++)
.flatMap(attempt -> reconnect(attempt, strategy)))
.subscribe();
return new MonoToListenableFutureAdapter<>(connectMono);
@@ -244,12 +244,9 @@ public class ReactorNettyTcpClient<P> implements TcpOperations<P> {
};
}
private <T> Function<Flux<T>, Publisher<?>> reconnectFunction(ReconnectStrategy reconnectStrategy) {
return flux -> flux
.scan(1, (count, element) -> count++)
.flatMap(attempt -> Optional.ofNullable(reconnectStrategy.getTimeToNextAttempt(attempt))
.map(time -> Mono.delay(Duration.ofMillis(time), this.scheduler))
.orElse(Mono.empty()));
private Publisher<? extends Long> reconnect(Integer attempt, ReconnectStrategy reconnectStrategy) {
Long time = reconnectStrategy.getTimeToNextAttempt(attempt);
return (time != null ? Mono.delay(Duration.ofMillis(time), this.scheduler) : Mono.empty());
}
@Override
@@ -342,7 +339,7 @@ public class ReactorNettyTcpClient<P> implements TcpOperations<P> {
private final ReactorNettyCodec<P> codec;
public StompMessageDecoder(ReactorNettyCodec<P> codec) {
StompMessageDecoder(ReactorNettyCodec<P> codec) {
this.codec = codec;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-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.
@@ -64,13 +64,11 @@ public class ReactorNettyTcpConnection<P> implements TcpConnection<P> {
}
@Override
@SuppressWarnings("deprecation")
public void onReadInactivity(Runnable runnable, long inactivityDuration) {
this.inbound.withConnection(conn -> conn.onReadIdle(inactivityDuration, runnable));
}
@Override
@SuppressWarnings("deprecation")
public void onWriteInactivity(Runnable runnable, long inactivityDuration) {
this.inbound.withConnection(conn -> conn.onWriteIdle(inactivityDuration, runnable));
}

View File

@@ -52,7 +52,6 @@ import org.springframework.util.ReflectionUtils;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
@@ -75,7 +74,7 @@ public class DefaultRSocketRequesterBuilderTests {
@BeforeEach
public void setup() {
this.transport = mock(ClientTransport.class);
given(this.transport.connect(anyInt())).willReturn(Mono.just(this.connection));
given(this.transport.connect()).willReturn(Mono.just(this.connection));
}
@@ -106,7 +105,7 @@ public class DefaultRSocketRequesterBuilderTests {
// RSocketStrategies and RSocketConnector configurers should have been called
verify(this.transport).connect(anyInt());
verify(this.transport).connect();
verify(strategiesConfigurer).accept(any(RSocketStrategies.Builder.class));
verify(factoryConfigurer).configure(any(io.rsocket.RSocketFactory.ClientRSocketFactory.class));
assertThat(this.connectorConfigurer.connector()).isNotNull();