Skip to content

Commit 40e4b89

Browse files
committed
Use Netty 4.2 only if available in defaults
1 parent 40d0b05 commit 40e4b89

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

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

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import io.netty.channel.ConnectTimeoutException;
2525
import io.netty.channel.EventLoopGroup;
2626
import io.netty.channel.MultiThreadIoEventLoopGroup;
27+
import io.netty.channel.nio.NioEventLoopGroup;
2728
import io.netty.channel.nio.NioIoHandler;
2829
import java.net.UnknownHostException;
2930
import java.security.cert.X509Certificate;
@@ -62,6 +63,8 @@ final class Utils {
6263
static final String SUBSCRIPTION_PROPERTY_FILTER_PREFIX = "filter.";
6364
static final String SUBSCRIPTION_PROPERTY_MATCH_UNFILTERED = "match-unfiltered";
6465

66+
static final boolean IS_NETTY_4_2;
67+
6568
static {
6669
Map<Short, String> labels = new HashMap<>();
6770
Arrays.stream(Constants.class.getDeclaredFields())
@@ -77,6 +80,14 @@ final class Utils {
7780
}
7881
});
7982
CONSTANT_LABELS = copyOf(labels);
83+
84+
boolean netty4_2 = true;
85+
try {
86+
Class.forName("io.netty.channel.MultiThreadIoEventLoopGroup");
87+
} catch (ClassNotFoundException e) {
88+
netty4_2 = false;
89+
}
90+
IS_NETTY_4_2 = netty4_2;
8091
}
8192

8293
static final AddressResolver DEFAULT_ADDRESS_RESOLVER = address -> address;
@@ -413,8 +424,15 @@ static Function<ClientConnectionType, String> defaultConnectionNamingStrategy(St
413424
prefixes.get(clientConnectionType) + sequences.get(clientConnectionType).getAndIncrement();
414425
}
415426

427+
@SuppressWarnings("deprecation")
416428
static EventLoopGroup eventLoopGroup() {
417-
return new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory());
429+
if (IS_NETTY_4_2) {
430+
System.out.println("NETTY 4.2");
431+
return new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory());
432+
} else {
433+
System.out.println("NETTY 4.1");
434+
return new NioEventLoopGroup();
435+
}
418436
}
419437

420438
static ByteBufAllocator byteBufAllocator() {

0 commit comments

Comments
 (0)