2424import io .netty .channel .ConnectTimeoutException ;
2525import io .netty .channel .EventLoopGroup ;
2626import io .netty .channel .MultiThreadIoEventLoopGroup ;
27+ import io .netty .channel .nio .NioEventLoopGroup ;
2728import io .netty .channel .nio .NioIoHandler ;
2829import java .net .UnknownHostException ;
2930import 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