Skip to content

Commit 59ae86c

Browse files
authored
Merge pull request #709 from rabbitmq/netty-4.2
Bump Netty to 4.2.0 References #731
2 parents 1c17aca + ee52e93 commit 59ae86c

15 files changed

+52
-64
lines changed

pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
<spotless.check.skip>true</spotless.check.skip>
5151
<slf4j.version>1.7.36</slf4j.version>
5252
<logback.version>1.2.13</logback.version>
53-
<netty.version>4.1.119.Final</netty.version>
53+
<netty.version>4.2.0.Final</netty.version>
5454
<proton-j.version>0.34.1</proton-j.version>
5555
<metrics.version>4.2.30</metrics.version>
5656
<micrometer.version>1.14.5</micrometer.version>

src/docs/asciidoc/api.adoc

+4-10
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,9 @@ TLS can be enabled by using the `rabbitmq-stream+tls` scheme in the URI.
8888
The default TLS port is 5551.
8989

9090
Use the `EnvironmentBuilder#tls` method to configure TLS.
91-
The most important setting is a `io.netty.handler.ssl.SslContext` instance,
92-
which is created and configured with the
93-
`io.netty.handler.ssl.SslContext#forClient` method. Note hostname verification
94-
is enabled by default.
91+
The most important setting is a `io.netty.handler.ssl.SslContext` instance, which is created and configured with the
92+
`io.netty.handler.ssl.SslContext#forClient` method.
93+
Note hostname verification is enabled by default.
9594

9695
The following snippet shows a common configuration, whereby
9796
the client is instructed to trust servers with certificates
@@ -242,15 +241,10 @@ Used as a prefix for connection names.
242241
|Configuration helper for TLS.
243242
|TLS is enabled if a `rabbitmq-stream+tls` URI is provided.
244243

245-
|`tls#hostnameVerification`
246-
|Enable or disable hostname verification.
247-
|Enabled by default.
248-
249244
|`tls#sslContext`
250245
|Set the `io.netty.handler.ssl.SslContext` used for the TLS connection.
251246
Use `io.netty.handler.ssl.SslContextBuilder#forClient` to configure it.
252-
The server certificate chain and the client private key are the typical
253-
elements that need to be configured.
247+
The server certificate chain, the client private key, and hostname verification are the usual elements that need to be configured.
254248
|The JDK trust manager and no client private key.
255249

256250
|`tls#trustEverything`

src/main/java/com/rabbitmq/stream/EnvironmentBuilder.java

+8-2
Original file line numberDiff line numberDiff line change
@@ -442,25 +442,31 @@ interface TlsConfiguration {
442442
* <p>Hostname verification is enabled by default.
443443
*
444444
* @return the TLS configuration helper
445+
* @deprecated use {@link SslContextBuilder#endpointIdentificationAlgorithm(String)} with {@link
446+
* #sslContext(SslContext)}
445447
*/
448+
@Deprecated(forRemoval = true)
446449
TlsConfiguration hostnameVerification();
447450

448451
/**
449452
* Enable or disable hostname verification.
450453
*
451454
* <p>Hostname verification is enabled by default.
452455
*
453-
* @param hostnameVerification
456+
* @param hostnameVerification whether to enable hostname verification or not
454457
* @return the TLS configuration helper
458+
* @deprecated use {@link SslContextBuilder#endpointIdentificationAlgorithm(String)} with {@link
459+
* #sslContext(SslContext)}
455460
*/
461+
@Deprecated(forRemoval = true)
456462
TlsConfiguration hostnameVerification(boolean hostnameVerification);
457463

458464
/**
459465
* Netty {@link SslContext} for TLS connections.
460466
*
461467
* <p>Use {@link SslContextBuilder#forClient()} to configure and create an instance.
462468
*
463-
* @param sslContext
469+
* @param sslContext the SSL context
464470
* @return the TLS configuration helper
465471
*/
466472
TlsConfiguration sslContext(SslContext sslContext);

src/main/java/com/rabbitmq/stream/impl/Client.java

+2-27
Original file line numberDiff line numberDiff line change
@@ -59,17 +59,7 @@
5959
import io.netty.buffer.ByteBuf;
6060
import io.netty.buffer.ByteBufAllocator;
6161
import io.netty.buffer.ByteBufOutputStream;
62-
import io.netty.channel.Channel;
63-
import io.netty.channel.ChannelFuture;
64-
import io.netty.channel.ChannelHandlerContext;
65-
import io.netty.channel.ChannelInboundHandlerAdapter;
66-
import io.netty.channel.ChannelInitializer;
67-
import io.netty.channel.ChannelOption;
68-
import io.netty.channel.ChannelOutboundHandlerAdapter;
69-
import io.netty.channel.ChannelPromise;
70-
import io.netty.channel.ConnectTimeoutException;
71-
import io.netty.channel.EventLoopGroup;
72-
import io.netty.channel.nio.NioEventLoopGroup;
62+
import io.netty.channel.*;
7363
import io.netty.channel.socket.SocketChannel;
7464
import io.netty.channel.socket.nio.NioSocketChannel;
7565
import io.netty.handler.codec.DecoderException;
@@ -106,9 +96,7 @@
10696
import java.util.function.Consumer;
10797
import java.util.function.Supplier;
10898
import java.util.function.ToLongFunction;
109-
import javax.net.ssl.SSLEngine;
11099
import javax.net.ssl.SSLHandshakeException;
111-
import javax.net.ssl.SSLParameters;
112100
import org.slf4j.Logger;
113101
import org.slf4j.LoggerFactory;
114102

@@ -248,7 +236,7 @@ public Client(ClientParameters parameters) {
248236
if (b.config().group() == null) {
249237
EventLoopGroup eventLoopGroup;
250238
if (parameters.eventLoopGroup == null) {
251-
this.eventLoopGroup = new NioEventLoopGroup();
239+
this.eventLoopGroup = Utils.eventLoopGroup();
252240
eventLoopGroup = this.eventLoopGroup;
253241
} else {
254242
this.eventLoopGroup = null;
@@ -293,13 +281,6 @@ public void initChannel(SocketChannel ch) {
293281
SslHandler sslHandler =
294282
parameters.sslContext.newHandler(ch.alloc(), parameters.host, parameters.port);
295283

296-
if (parameters.tlsHostnameVerification) {
297-
SSLEngine sslEngine = sslHandler.engine();
298-
SSLParameters sslParameters = sslEngine.getSSLParameters();
299-
sslParameters.setEndpointIdentificationAlgorithm("HTTPS");
300-
sslEngine.setSSLParameters(sslParameters);
301-
}
302-
303284
ch.pipeline().addFirst("ssl", sslHandler);
304285
}
305286
channelCustomizer.accept(ch);
@@ -2407,7 +2388,6 @@ public static class ClientParameters {
24072388
private ChunkChecksum chunkChecksum = JdkChunkChecksum.CRC32_SINGLETON;
24082389
private MetricsCollector metricsCollector = NoOpMetricsCollector.SINGLETON;
24092390
private SslContext sslContext;
2410-
private boolean tlsHostnameVerification = true;
24112391
private ByteBufAllocator byteBufAllocator;
24122392
private Duration rpcTimeout;
24132393
private Consumer<Channel> channelCustomizer = noOpConsumer();
@@ -2564,11 +2544,6 @@ public ClientParameters sslContext(SslContext sslContext) {
25642544
return this;
25652545
}
25662546

2567-
public ClientParameters tlsHostnameVerification(boolean tlsHostnameVerification) {
2568-
this.tlsHostnameVerification = tlsHostnameVerification;
2569-
return this;
2570-
}
2571-
25722547
public ClientParameters compressionCodecFactory(
25732548
CompressionCodecFactory compressionCodecFactory) {
25742549
this.compressionCodecFactory = compressionCodecFactory;

src/main/java/com/rabbitmq/stream/impl/StreamEnvironment.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
3939
import io.netty.buffer.ByteBufAllocator;
4040
import io.netty.channel.EventLoopGroup;
41-
import io.netty.channel.nio.NioEventLoopGroup;
4241
import io.netty.handler.ssl.SslContext;
4342
import io.netty.handler.ssl.SslContextBuilder;
4443
import java.io.IOException;
@@ -130,12 +129,13 @@ class StreamEnvironment implements Environment {
130129
try {
131130
SslContext sslContext =
132131
tlsConfiguration.sslContext() == null
133-
? SslContextBuilder.forClient().build()
132+
? SslContextBuilder.forClient()
133+
.endpointIdentificationAlgorithm(
134+
tlsConfiguration.hostnameVerificationEnabled() ? "HTTPS" : null)
135+
.build()
134136
: tlsConfiguration.sslContext();
135137

136138
clientParametersPrototype.sslContext(sslContext);
137-
clientParametersPrototype.tlsHostnameVerification(
138-
tlsConfiguration.hostnameVerificationEnabled());
139139

140140
} catch (SSLException e) {
141141
throw new StreamException("Error while creating Netty SSL context", e);
@@ -212,7 +212,7 @@ class StreamEnvironment implements Environment {
212212
this.addresses.size(), 1, "rabbitmq-stream-locator-connection-");
213213

214214
if (clientParametersPrototype.eventLoopGroup == null) {
215-
this.eventLoopGroup = new NioEventLoopGroup();
215+
this.eventLoopGroup = Utils.eventLoopGroup();
216216
this.clientParametersPrototype =
217217
clientParametersPrototype.duplicate().eventLoopGroup(this.eventLoopGroup);
218218
} else {

src/main/java/com/rabbitmq/stream/impl/StreamEnvironmentBuilder.java

+3
Original file line numberDiff line numberDiff line change
@@ -373,12 +373,14 @@ private DefaultTlsConfiguration(EnvironmentBuilder environmentBuilder) {
373373
}
374374

375375
@Override
376+
@SuppressWarnings("removal")
376377
public TlsConfiguration hostnameVerification() {
377378
this.hostnameVerification = true;
378379
return this;
379380
}
380381

381382
@Override
383+
@SuppressWarnings("removal")
382384
public TlsConfiguration hostnameVerification(boolean hostnameVerification) {
383385
this.hostnameVerification = hostnameVerification;
384386
return this;
@@ -400,6 +402,7 @@ public TlsConfiguration trustEverything() {
400402
this.sslContext(
401403
SslContextBuilder.forClient()
402404
.trustManager(Utils.TRUST_EVERYTHING_TRUST_MANAGER)
405+
.endpointIdentificationAlgorithm("NONE")
403406
.build());
404407
} catch (SSLException e) {
405408
throw new StreamException("Error while creating Netty SSL context", e);

src/main/java/com/rabbitmq/stream/impl/Utils.java

+7
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
import com.rabbitmq.stream.*;
2121
import com.rabbitmq.stream.impl.Client.ClientParameters;
2222
import io.netty.channel.ConnectTimeoutException;
23+
import io.netty.channel.EventLoopGroup;
24+
import io.netty.channel.MultiThreadIoEventLoopGroup;
25+
import io.netty.channel.nio.NioIoHandler;
2326
import java.net.UnknownHostException;
2427
import java.security.cert.X509Certificate;
2528
import java.time.Duration;
@@ -408,6 +411,10 @@ static Function<ClientConnectionType, String> defaultConnectionNamingStrategy(St
408411
prefixes.get(clientConnectionType) + sequences.get(clientConnectionType).getAndIncrement();
409412
}
410413

414+
static EventLoopGroup eventLoopGroup() {
415+
return new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory());
416+
}
417+
411418
/*
412419
class to help testing SAC on super streams
413420
*/

src/test/java/com/rabbitmq/stream/DefaultEnvironmentTest.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919

2020
import com.rabbitmq.stream.impl.Client;
2121
import io.netty.channel.EventLoopGroup;
22-
import io.netty.channel.nio.NioEventLoopGroup;
22+
import io.netty.channel.MultiThreadIoEventLoopGroup;
23+
import io.netty.channel.nio.NioIoHandler;
2324
import java.util.UUID;
2425
import org.junit.jupiter.api.AfterAll;
2526
import org.junit.jupiter.api.BeforeAll;
@@ -31,7 +32,7 @@ public class DefaultEnvironmentTest {
3132

3233
@BeforeAll
3334
static void initAll() {
34-
eventLoopGroup = new NioEventLoopGroup();
35+
eventLoopGroup = new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory());
3536
}
3637

3738
@AfterAll

src/test/java/com/rabbitmq/stream/docs/EnvironmentUsage.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@
1919
import com.rabbitmq.stream.observation.micrometer.MicrometerObservationCollectorBuilder;
2020
import io.micrometer.observation.ObservationRegistry;
2121
import io.netty.channel.EventLoopGroup;
22+
import io.netty.channel.MultiThreadIoEventLoopGroup;
2223
import io.netty.channel.epoll.EpollEventLoopGroup;
24+
import io.netty.channel.epoll.EpollIoHandler;
2325
import io.netty.channel.epoll.EpollSocketChannel;
2426
import io.netty.handler.ssl.SslContext;
2527
import io.netty.handler.ssl.SslContextBuilder;
@@ -140,7 +142,9 @@ void deleteStream() {
140142

141143
void nativeEpoll() {
142144
// tag::native-epoll[]
143-
EventLoopGroup epollEventLoopGroup = new EpollEventLoopGroup(); // <1>
145+
EventLoopGroup epollEventLoopGroup = new MultiThreadIoEventLoopGroup( // <1>
146+
EpollIoHandler.newFactory() // <1>
147+
); // <1>
144148
Environment environment = Environment.builder()
145149
.netty() // <2>
146150
.eventLoopGroup(epollEventLoopGroup) // <3>

src/test/java/com/rabbitmq/stream/impl/AlarmsTest.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
import com.rabbitmq.stream.Producer;
3333
import com.rabbitmq.stream.StreamException;
3434
import io.netty.channel.EventLoopGroup;
35-
import io.netty.channel.nio.NioEventLoopGroup;
3635
import java.time.Duration;
3736
import java.util.concurrent.CountDownLatch;
3837
import java.util.concurrent.atomic.AtomicReference;
@@ -56,7 +55,7 @@ public class AlarmsTest {
5655

5756
@BeforeAll
5857
static void initAll() {
59-
eventLoopGroup = new NioEventLoopGroup();
58+
eventLoopGroup = Utils.eventLoopGroup();
6059
}
6160

6261
@AfterAll

src/test/java/com/rabbitmq/stream/impl/MqttInteroperabilityTest.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import com.rabbitmq.stream.OffsetSpecification;
2828
import com.rabbitmq.stream.amqp.UnsignedByte;
2929
import io.netty.channel.EventLoopGroup;
30-
import io.netty.channel.nio.NioEventLoopGroup;
3130
import java.nio.charset.StandardCharsets;
3231
import java.util.UUID;
3332
import java.util.concurrent.CountDownLatch;
@@ -57,7 +56,7 @@ public class MqttInteroperabilityTest {
5756

5857
@BeforeAll
5958
static void initAll() {
60-
eventLoopGroup = new NioEventLoopGroup();
59+
eventLoopGroup = Utils.eventLoopGroup();
6160
}
6261

6362
@AfterAll

src/test/java/com/rabbitmq/stream/impl/StompInteroperabilityTest.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222

2323
import com.rabbitmq.stream.*;
2424
import io.netty.channel.EventLoopGroup;
25-
import io.netty.channel.nio.NioEventLoopGroup;
2625
import java.io.BufferedReader;
2726
import java.io.IOException;
2827
import java.io.InputStreamReader;
@@ -66,7 +65,7 @@ public class StompInteroperabilityTest {
6665

6766
@BeforeAll
6867
static void initAll() {
69-
eventLoopGroup = new NioEventLoopGroup();
68+
eventLoopGroup = Utils.eventLoopGroup();
7069
}
7170

7271
@AfterAll

src/test/java/com/rabbitmq/stream/impl/StreamEnvironmentTest.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@
5151
import com.rabbitmq.stream.impl.TestUtils.DisabledIfTlsNotEnabled;
5252
import io.netty.channel.Channel;
5353
import io.netty.channel.EventLoopGroup;
54-
import io.netty.channel.epoll.EpollEventLoopGroup;
54+
import io.netty.channel.MultiThreadIoEventLoopGroup;
55+
import io.netty.channel.epoll.EpollIoHandler;
5556
import io.netty.channel.epoll.EpollSocketChannel;
5657
import io.netty.handler.ssl.SslHandler;
5758
import java.net.ConnectException;
@@ -723,7 +724,8 @@ void nettyInitializersAreCalled() {
723724
@EnabledIfSystemProperty(named = "os.arch", matches = "amd64")
724725
void nativeEpollWorksOnLinux() {
725726
int messageCount = 10_000;
726-
EventLoopGroup epollEventLoopGroup = new EpollEventLoopGroup();
727+
EventLoopGroup epollEventLoopGroup =
728+
new MultiThreadIoEventLoopGroup(EpollIoHandler.newFactory());
727729
try {
728730
Set<Channel> channels = ConcurrentHashMap.newKeySet();
729731
try (Environment env =

src/test/java/com/rabbitmq/stream/impl/TestUtils.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242
import com.rabbitmq.stream.impl.Client.Response;
4343
import com.rabbitmq.stream.impl.Client.StreamMetadata;
4444
import io.netty.channel.EventLoopGroup;
45-
import io.netty.channel.nio.NioEventLoopGroup;
4645
import io.vavr.Tuple2;
4746
import java.io.IOException;
4847
import java.lang.annotation.Documented;
@@ -627,7 +626,7 @@ static EventLoopGroup eventLoopGroup(ExtensionContext context) {
627626

628627
@Override
629628
public void beforeAll(ExtensionContext context) {
630-
store(context).put("nettyEventLoopGroup", new NioEventLoopGroup());
629+
store(context).put("nettyEventLoopGroup", Utils.eventLoopGroup());
631630
}
632631

633632
@Override

src/test/java/com/rabbitmq/stream/impl/TlsTest.java

+6-6
Original file line numberDiff line numberDiff line change
@@ -295,12 +295,12 @@ void hostnameVerificationShouldFailWhenSettingHostToLoopbackInterface() throws E
295295
@Test
296296
void shouldConnectWhenSettingHostToLoopbackInterfaceAndDisablingHostnameVerification()
297297
throws Exception {
298-
SslContext context = SslContextBuilder.forClient().trustManager(caCertificate()).build();
299-
cf.get(
300-
new ClientParameters()
301-
.sslContext(context)
302-
.host("127.0.0.1")
303-
.tlsHostnameVerification(false));
298+
SslContext context =
299+
SslContextBuilder.forClient()
300+
.endpointIdentificationAlgorithm(null)
301+
.trustManager(caCertificate())
302+
.build();
303+
cf.get(new ClientParameters().sslContext(context).host("127.0.0.1"));
304304
}
305305

306306
@Test

0 commit comments

Comments
 (0)