1717
1818import static com .rabbitmq .client .ConnectionFactory .computeDefaultTlsProtocol ;
1919import static com .rabbitmq .perf .OptionsUtils .forEach ;
20+ import static com .rabbitmq .perf .Tuples .pair ;
2021import static com .rabbitmq .perf .Utils .strArg ;
2122import static java .lang .String .format ;
2223import static java .util .Arrays .asList ;
3334import com .rabbitmq .client .impl .DefaultCredentialsRefreshService .DefaultCredentialsRefreshServiceBuilder ;
3435import com .rabbitmq .client .impl .DefaultExceptionHandler ;
3536import com .rabbitmq .perf .Metrics .ConfigurationContext ;
37+ import com .rabbitmq .perf .Tuples .Pair ;
3638import com .rabbitmq .perf .Utils .GsonOAuth2ClientCredentialsGrantCredentialsProvider ;
3739import com .rabbitmq .perf .metrics .CompositeMetricsFormatter ;
3840import com .rabbitmq .perf .metrics .CsvMetricsFormatter ;
4244import com .rabbitmq .perf .metrics .MetricsFormatterFactory .Context ;
4345import io .micrometer .core .instrument .composite .CompositeMeterRegistry ;
4446import io .netty .bootstrap .Bootstrap ;
47+ import io .netty .channel .Channel ;
4548import io .netty .channel .EventLoopGroup ;
4649import io .netty .channel .IoHandlerFactory ;
4750import io .netty .channel .MultiThreadIoEventLoopGroup ;
51+ import io .netty .channel .epoll .Epoll ;
4852import io .netty .channel .epoll .EpollIoHandler ;
4953import io .netty .channel .epoll .EpollSocketChannel ;
54+ import io .netty .channel .kqueue .KQueue ;
55+ import io .netty .channel .kqueue .KQueueIoHandler ;
56+ import io .netty .channel .kqueue .KQueueSocketChannel ;
5057import io .netty .channel .nio .NioIoHandler ;
58+ import io .netty .channel .socket .nio .NioSocketChannel ;
5159import java .io .*;
5260import java .math .BigDecimal ;
5361import java .nio .charset .Charset ;
6371import java .util .function .BooleanSupplier ;
6472import java .util .function .Consumer ;
6573import java .util .function .Function ;
74+ import java .util .function .Supplier ;
6675import java .util .stream .Collectors ;
6776import javax .net .ssl .SSLContext ;
6877import javax .net .ssl .TrustManager ;
@@ -860,10 +869,10 @@ private static void configureNettyIfRequested(
860869 if (netty (cmd )) {
861870 int nbThreads = Utils .intArg (cmd , "ntyt" , -1 );
862871 boolean epoll = hasOption (cmd , "ntyep" );
863- IoHandlerFactory ioHandlerFactory =
864- epoll ? EpollIoHandler . newFactory () : NioIoHandler . newFactory ( );
865- Consumer < Bootstrap > bootstrapCustomizer =
866- epoll ? b -> b .channel (EpollSocketChannel . class ) : b -> {} ;
872+ boolean kqueue = hasOption ( cmd , "ntykq" );
873+ Pair < IoHandlerFactory , Class <? extends Channel >> io = nettyIo ( epoll , kqueue );
874+ IoHandlerFactory ioHandlerFactory = io . v1 ();
875+ Consumer < Bootstrap > bootstrapCustomizer = b -> b .channel (io . v2 ()) ;
867876 EventLoopGroup eventLoopGroup =
868877 nbThreads > 0
869878 ? new MultiThreadIoEventLoopGroup (nbThreads , ioHandlerFactory )
@@ -873,11 +882,32 @@ private static void configureNettyIfRequested(
873882 }
874883 }
875884
885+ private static Pair <IoHandlerFactory , Class <? extends Channel >> nettyIo (
886+ boolean epoll , boolean kqueue ) {
887+ Supplier <Pair <IoHandlerFactory , Class <? extends Channel >>> result =
888+ () -> pair (NioIoHandler .newFactory (), NioSocketChannel .class );
889+ if (epoll ) {
890+ if (Epoll .isAvailable ()) {
891+ result = () -> pair (EpollIoHandler .newFactory (), EpollSocketChannel .class );
892+ } else {
893+ LOGGER .warn ("epoll not available, using Java NIO instead" );
894+ }
895+ } else if (kqueue ) {
896+ if (KQueue .isAvailable ()) {
897+ result = () -> pair (KQueueIoHandler .newFactory (), KQueueSocketChannel .class );
898+ } else {
899+ LOGGER .warn ("kqueue not available, using Java NIO instead" );
900+ }
901+ }
902+ return result .get ();
903+ }
904+
876905 private static boolean netty (CommandLineProxy cmd ) {
877906 boolean netty = hasOption (cmd , "nty" );
878907 int nbThreads = Utils .intArg (cmd , "ntyt" , -1 );
879908 boolean epoll = hasOption (cmd , "ntyep" );
880- return netty || nbThreads > 0 || epoll ;
909+ boolean kqueue = hasOption (cmd , "ntykq" );
910+ return netty || nbThreads > 0 || epoll || kqueue ;
881911 }
882912
883913 static MulticastSet .CompletionHandler getCompletionHandler (
@@ -1460,7 +1490,12 @@ static Options getOptions() {
14601490 "netty-epoll" ,
14611491 false ,
14621492 "use Netty's native epoll transport (Linux x86-64 only)" ));
1463-
1493+ options .addOption (
1494+ new Option (
1495+ "ntykq" ,
1496+ "netty-kqueue" ,
1497+ false ,
1498+ "use Netty's native kqueue transport (macOS aarch64 only)" ));
14641499 return options ;
14651500 }
14661501
0 commit comments