Skip to content

Remove Java NIO frame handler #1672

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 1 addition & 79 deletions src/main/java/com/rabbitmq/client/ConnectionFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
import static java.util.concurrent.TimeUnit.MINUTES;

import com.rabbitmq.client.impl.*;
import com.rabbitmq.client.impl.nio.NioParams;
import com.rabbitmq.client.impl.nio.SocketChannelFrameHandlerFactory;
import com.rabbitmq.client.impl.recovery.AutorecoveringConnection;
import com.rabbitmq.client.impl.recovery.RecoveredQueueNameSupplier;
import com.rabbitmq.client.impl.recovery.RetryHandler;
Expand Down Expand Up @@ -154,11 +152,9 @@ public class ConnectionFactory implements Cloneable {
private MetricsCollector metricsCollector;
private ObservationCollector observationCollector = ObservationCollector.NO_OP;

private boolean nio = false;
private boolean netty = false;
private FrameHandlerFactory frameHandlerFactory;
private final NettyConfiguration nettyConf = new NettyConfiguration(this);
private NioParams nioParams = new NioParams();

private SslContextFactory sslContextFactory;

Expand Down Expand Up @@ -917,9 +913,6 @@ public ConnectionFactory useSslProtocol(SSLContext context) {
* com.rabbitmq.client.ConnectionFactory.NettyConfiguration#sslContext(io.netty.handler.ssl.SslContext)}
* instead.
*
* @see NioParams#enableHostnameVerification()
* @see NioParams#setSslEngineConfigurator(SslEngineConfigurator)
* @see SslEngineConfigurators#ENABLE_HOSTNAME_VERIFICATION
* @see SocketConfigurators#ENABLE_HOSTNAME_VERIFICATION
* @see ConnectionFactory#useSslProtocol(String)
* @see ConnectionFactory#useSslProtocol(SSLContext)
Expand All @@ -928,18 +921,10 @@ public ConnectionFactory useSslProtocol(SSLContext context) {
* @since 5.4.0
*/
public ConnectionFactory enableHostnameVerification() {
enableHostnameVerificationForNio();
enableHostnameVerificationForBlockingIo();
return this;
}

protected void enableHostnameVerificationForNio() {
if (this.nioParams == null) {
this.nioParams = new NioParams();
}
this.nioParams = this.nioParams.enableHostnameVerification();
}

protected void enableHostnameVerificationForBlockingIo() {
if (this.socketConf == null) {
this.socketConf =
Expand Down Expand Up @@ -1076,21 +1061,7 @@ public ConnectionFactory setCredentialsRefreshService(
}

protected synchronized FrameHandlerFactory createFrameHandlerFactory() throws IOException {
if (nio) {
if (this.frameHandlerFactory == null) {
if (this.nioParams.getNioExecutor() == null && this.nioParams.getThreadFactory() == null) {
this.nioParams.setThreadFactory(getThreadFactory());
}
this.frameHandlerFactory =
new SocketChannelFrameHandlerFactory(
connectionTimeout,
nioParams,
isSSL(),
sslContextFactory,
this.maxInboundMessageBodySize);
}
return this.frameHandlerFactory;
} else if (netty) {
if (netty) {
if (this.frameHandlerFactory == null) {
this.frameHandlerFactory =
new NettyFrameHandlerFactory(
Expand Down Expand Up @@ -1659,59 +1630,11 @@ public ConnectionFactory setRecoveryDelayHandler(
return this;
}

/**
* Sets the parameters when using NIO.
*
* @param nioParams
* @see NioParams
* @deprecated user {@link #netty()} instead
*/
@Deprecated
public ConnectionFactory setNioParams(NioParams nioParams) {
this.nioParams = nioParams;
return this;
}

/**
* Retrieve the parameters for NIO mode.
*
* @return
* @deprecated Use {@link #netty()}
*/
@Deprecated
public NioParams getNioParams() {
return nioParams;
}

/**
* Use non-blocking IO (NIO) for communication with the server. With NIO, several connections
* created from the same {@link ConnectionFactory} can use the same IO thread.
*
* <p>A client process using a lot of not-so-active connections can benefit from NIO, as it would
* use fewer threads than with the traditional, blocking IO mode.
*
* <p>Use {@link NioParams} to tune NIO and a {@link SocketChannelConfigurator} to configure the
* underlying {@link java.nio.channels.SocketChannel}s for connections.
*
* @see NioParams
* @see SocketChannelConfigurator
* @see java.nio.channels.SocketChannel
* @see java.nio.channels.Selector
* @deprecated Use {@link #netty()} instead
*/
@Deprecated
public ConnectionFactory useNio() {
this.nio = true;
this.netty = false;
return this;
}

/**
* Use blocking IO for communication with the server. With blocking IO, each connection creates
* its own thread to read data from the server.
*/
public ConnectionFactory useBlockingIo() {
this.nio = false;
this.netty = false;
return this;
}
Expand Down Expand Up @@ -1885,7 +1808,6 @@ public ConnectionFactory setTrafficListener(TrafficListener trafficListener) {

private ConnectionFactory useNetty() {
this.netty = true;
this.nio = false;
return this;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2017-2023 Broadcom. All Rights Reserved. The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries.
// Copyright (c) 2017-2025 Broadcom. All Rights Reserved. The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries.
//
// This software, the RabbitMQ Java client library, is triple-licensed under the
// Mozilla Public License 2.0 ("MPL"), the GNU General Public License version 2
Expand All @@ -16,7 +16,6 @@
package com.rabbitmq.client;

import com.rabbitmq.client.impl.AMQConnection;
import com.rabbitmq.client.impl.nio.NioParams;

import javax.net.ssl.*;
import java.io.FileInputStream;
Expand Down Expand Up @@ -69,12 +68,6 @@ public class ConnectionFactoryConfigurator {
public static final String CONNECTION_RECOVERY_INTERVAL = "connection.recovery.interval";
public static final String CHANNEL_RPC_TIMEOUT = "channel.rpc.timeout";
public static final String CHANNEL_SHOULD_CHECK_RPC_RESPONSE_TYPE = "channel.should.check.rpc.response.type";
public static final String USE_NIO = "use.nio";
public static final String NIO_READ_BYTE_BUFFER_SIZE = "nio.read.byte.buffer.size";
public static final String NIO_WRITE_BYTE_BUFFER_SIZE = "nio.write.byte.buffer.size";
public static final String NIO_NB_IO_THREADS = "nio.nb.io.threads";
public static final String NIO_WRITE_ENQUEUING_TIMEOUT_IN_MS = "nio.write.enqueuing.timeout.in.ms";
public static final String NIO_WRITE_QUEUE_CAPACITY = "nio.write.queue.capacity";
public static final String SSL_ALGORITHM = "ssl.algorithm";
public static final String SSL_ENABLED = "ssl.enabled";
public static final String SSL_KEY_STORE = "ssl.key.store";
Expand Down Expand Up @@ -225,35 +218,6 @@ public static void load(ConnectionFactory cf, Map<String, String> properties, St
cf.setChannelShouldCheckRpcResponseType(Boolean.valueOf(channelShouldCheckRpcResponseType));
}

String useNio = lookUp(USE_NIO, properties, prefix);
if (useNio != null && Boolean.valueOf(useNio)) {
cf.useNio();

NioParams nioParams = new NioParams();

String readByteBufferSize = lookUp(NIO_READ_BYTE_BUFFER_SIZE, properties, prefix);
if (readByteBufferSize != null) {
nioParams.setReadByteBufferSize(Integer.valueOf(readByteBufferSize));
}
String writeByteBufferSize = lookUp(NIO_WRITE_BYTE_BUFFER_SIZE, properties, prefix);
if (writeByteBufferSize != null) {
nioParams.setWriteByteBufferSize(Integer.valueOf(writeByteBufferSize));
}
String nbIoThreads = lookUp(NIO_NB_IO_THREADS, properties, prefix);
if (nbIoThreads != null) {
nioParams.setNbIoThreads(Integer.valueOf(nbIoThreads));
}
String writeEnqueuingTime = lookUp(NIO_WRITE_ENQUEUING_TIMEOUT_IN_MS, properties, prefix);
if (writeEnqueuingTime != null) {
nioParams.setWriteEnqueuingTimeoutInMs(Integer.valueOf(writeEnqueuingTime));
}
String writeQueueCapacity = lookUp(NIO_WRITE_QUEUE_CAPACITY, properties, prefix);
if (writeQueueCapacity != null) {
nioParams.setWriteQueueCapacity(Integer.valueOf(writeQueueCapacity));
}
cf.setNioParams(nioParams);
}

String useSsl = lookUp(SSL_ENABLED, properties, prefix);
if (useSsl != null && Boolean.valueOf(useSsl)) {
setUpSsl(cf, properties, prefix);
Expand Down

This file was deleted.

50 changes: 0 additions & 50 deletions src/main/java/com/rabbitmq/client/SocketChannelConfigurator.java

This file was deleted.

Loading