Make netty channel timeout configurable
This commit is contained in:
@@ -51,8 +51,9 @@ public class BrokerConstants {
|
|||||||
public static final String HOST = "0.0.0.0";
|
public static final String HOST = "0.0.0.0";
|
||||||
public static final String NEED_CLIENT_AUTH = "need_client_auth";
|
public static final String NEED_CLIENT_AUTH = "need_client_auth";
|
||||||
public static final String HAZELCAST_CONFIGURATION = "hazelcast.configuration";
|
public static final String HAZELCAST_CONFIGURATION = "hazelcast.configuration";
|
||||||
public static final String NETTY_SO_BACKLOG = "netty.so_backlog";
|
public static final String NETTY_SO_BACKLOG_PROPERTY_NAME = "netty.so_backlog";
|
||||||
public static final String NETTY_SO_REUSEADDR = "netty.so_reuseaddr";
|
public static final String NETTY_SO_REUSEADDR_PROPERTY_NAME = "netty.so_reuseaddr";
|
||||||
public static final String NETTY_TCP_NODELAY = "netty.tcp_nodelay";
|
public static final String NETTY_TCP_NODELAY_PROPERTY_NAME = "netty.tcp_nodelay";
|
||||||
public static final String NETTY_SO_KEEPALIVE = "netty.so_keepalive";
|
public static final String NETTY_SO_KEEPALIVE_PROPERTY_NAME = "netty.so_keepalive";
|
||||||
|
public static final String NETTY_CHANNEL_TIMEOUT_SECONDS_PROPERTY_NAME = "netty.channel_timeout.seconds";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,7 +17,6 @@ package io.moquette.server.netty;
|
|||||||
|
|
||||||
import io.moquette.BrokerConstants;
|
import io.moquette.BrokerConstants;
|
||||||
import static io.moquette.BrokerConstants.*;
|
import static io.moquette.BrokerConstants.*;
|
||||||
import io.moquette.parser.commons.Constants;
|
|
||||||
import io.moquette.parser.netty.MQTTDecoder;
|
import io.moquette.parser.netty.MQTTDecoder;
|
||||||
import io.moquette.parser.netty.MQTTEncoder;
|
import io.moquette.parser.netty.MQTTEncoder;
|
||||||
import io.moquette.spi.security.ISslContextCreator;
|
import io.moquette.spi.security.ISslContextCreator;
|
||||||
@@ -99,15 +98,18 @@ public class NettyAcceptor implements ServerAcceptor {
|
|||||||
private boolean nettySoReuseaddr;
|
private boolean nettySoReuseaddr;
|
||||||
private boolean nettyTcpNodelay;
|
private boolean nettyTcpNodelay;
|
||||||
private boolean nettySoKeepalive;
|
private boolean nettySoKeepalive;
|
||||||
|
private int nettyChannelTimeoutSeconds;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void initialize(ProtocolProcessor processor, IConfig props, ISslContextCreator sslCtxCreator) throws IOException {
|
public void initialize(ProtocolProcessor processor, IConfig props, ISslContextCreator sslCtxCreator) throws IOException {
|
||||||
LOG.info("Initializing Netty acceptor...");
|
LOG.info("Initializing Netty acceptor...");
|
||||||
|
|
||||||
nettySoBacklog = Integer.parseInt(props.getProperty(BrokerConstants.NETTY_SO_BACKLOG, "128"));
|
nettySoBacklog = Integer.parseInt(props.getProperty(BrokerConstants.NETTY_SO_BACKLOG_PROPERTY_NAME, "128"));
|
||||||
nettySoReuseaddr = Boolean.parseBoolean(props.getProperty(BrokerConstants.NETTY_SO_REUSEADDR, "true"));
|
nettySoReuseaddr = Boolean.parseBoolean(props.getProperty(BrokerConstants.NETTY_SO_REUSEADDR_PROPERTY_NAME, "true"));
|
||||||
nettyTcpNodelay = Boolean.parseBoolean(props.getProperty(BrokerConstants.NETTY_TCP_NODELAY, "true"));
|
nettyTcpNodelay = Boolean.parseBoolean(props.getProperty(BrokerConstants.NETTY_TCP_NODELAY_PROPERTY_NAME, "true"));
|
||||||
nettySoKeepalive = Boolean.parseBoolean(props.getProperty(BrokerConstants.NETTY_SO_KEEPALIVE, "true"));
|
nettySoKeepalive = Boolean.parseBoolean(props.getProperty(BrokerConstants.NETTY_SO_KEEPALIVE_PROPERTY_NAME, "true"));
|
||||||
|
nettyChannelTimeoutSeconds = Integer
|
||||||
|
.parseInt(props.getProperty(BrokerConstants.NETTY_CHANNEL_TIMEOUT_SECONDS_PROPERTY_NAME, "10"));
|
||||||
|
|
||||||
m_bossGroup = new NioEventLoopGroup();
|
m_bossGroup = new NioEventLoopGroup();
|
||||||
m_workerGroup = new NioEventLoopGroup();
|
m_workerGroup = new NioEventLoopGroup();
|
||||||
@@ -173,7 +175,7 @@ public class NettyAcceptor implements ServerAcceptor {
|
|||||||
initFactory(host, port, "TCP MQTT", new PipelineInitializer() {
|
initFactory(host, port, "TCP MQTT", new PipelineInitializer() {
|
||||||
@Override
|
@Override
|
||||||
void init(ChannelPipeline pipeline) {
|
void init(ChannelPipeline pipeline) {
|
||||||
pipeline.addFirst("idleStateHandler", new IdleStateHandler(0, 0, Constants.DEFAULT_CONNECT_TIMEOUT));
|
pipeline.addFirst("idleStateHandler", new IdleStateHandler(0, 0, nettyChannelTimeoutSeconds));
|
||||||
pipeline.addAfter("idleStateHandler", "idleEventHandler", timeoutHandler);
|
pipeline.addAfter("idleStateHandler", "idleEventHandler", timeoutHandler);
|
||||||
// pipeline.addLast("logger", new LoggingHandler("Netty", LogLevel.ERROR));
|
// pipeline.addLast("logger", new LoggingHandler("Netty", LogLevel.ERROR));
|
||||||
pipeline.addFirst("bytemetrics", new BytesMetricsHandler(m_bytesMetricsCollector));
|
pipeline.addFirst("bytemetrics", new BytesMetricsHandler(m_bytesMetricsCollector));
|
||||||
@@ -208,7 +210,7 @@ public class NettyAcceptor implements ServerAcceptor {
|
|||||||
pipeline.addLast("webSocketHandler", new WebSocketServerProtocolHandler("/mqtt", MQTT_SUBPROTOCOL_CSV_LIST));
|
pipeline.addLast("webSocketHandler", new WebSocketServerProtocolHandler("/mqtt", MQTT_SUBPROTOCOL_CSV_LIST));
|
||||||
pipeline.addLast("ws2bytebufDecoder", new WebSocketFrameToByteBufDecoder());
|
pipeline.addLast("ws2bytebufDecoder", new WebSocketFrameToByteBufDecoder());
|
||||||
pipeline.addLast("bytebuf2wsEncoder", new ByteBufToWebSocketFrameEncoder());
|
pipeline.addLast("bytebuf2wsEncoder", new ByteBufToWebSocketFrameEncoder());
|
||||||
pipeline.addFirst("idleStateHandler", new IdleStateHandler(0, 0, Constants.DEFAULT_CONNECT_TIMEOUT));
|
pipeline.addFirst("idleStateHandler", new IdleStateHandler(0, 0, nettyChannelTimeoutSeconds));
|
||||||
pipeline.addAfter("idleStateHandler", "idleEventHandler", timeoutHandler);
|
pipeline.addAfter("idleStateHandler", "idleEventHandler", timeoutHandler);
|
||||||
pipeline.addFirst("bytemetrics", new BytesMetricsHandler(m_bytesMetricsCollector));
|
pipeline.addFirst("bytemetrics", new BytesMetricsHandler(m_bytesMetricsCollector));
|
||||||
pipeline.addLast("decoder", new MQTTDecoder());
|
pipeline.addLast("decoder", new MQTTDecoder());
|
||||||
@@ -241,7 +243,7 @@ public class NettyAcceptor implements ServerAcceptor {
|
|||||||
@Override
|
@Override
|
||||||
void init(ChannelPipeline pipeline) throws Exception {
|
void init(ChannelPipeline pipeline) throws Exception {
|
||||||
pipeline.addLast("ssl", createSslHandler(sslContext, needsClientAuth));
|
pipeline.addLast("ssl", createSslHandler(sslContext, needsClientAuth));
|
||||||
pipeline.addFirst("idleStateHandler", new IdleStateHandler(0, 0, Constants.DEFAULT_CONNECT_TIMEOUT));
|
pipeline.addFirst("idleStateHandler", new IdleStateHandler(0, 0, nettyChannelTimeoutSeconds));
|
||||||
pipeline.addAfter("idleStateHandler", "idleEventHandler", timeoutHandler);
|
pipeline.addAfter("idleStateHandler", "idleEventHandler", timeoutHandler);
|
||||||
//pipeline.addLast("logger", new LoggingHandler("Netty", LogLevel.ERROR));
|
//pipeline.addLast("logger", new LoggingHandler("Netty", LogLevel.ERROR));
|
||||||
pipeline.addFirst("bytemetrics", new BytesMetricsHandler(m_bytesMetricsCollector));
|
pipeline.addFirst("bytemetrics", new BytesMetricsHandler(m_bytesMetricsCollector));
|
||||||
@@ -278,7 +280,7 @@ public class NettyAcceptor implements ServerAcceptor {
|
|||||||
pipeline.addLast("webSocketHandler", new WebSocketServerProtocolHandler("/mqtt", MQTT_SUBPROTOCOL_CSV_LIST));
|
pipeline.addLast("webSocketHandler", new WebSocketServerProtocolHandler("/mqtt", MQTT_SUBPROTOCOL_CSV_LIST));
|
||||||
pipeline.addLast("ws2bytebufDecoder", new WebSocketFrameToByteBufDecoder());
|
pipeline.addLast("ws2bytebufDecoder", new WebSocketFrameToByteBufDecoder());
|
||||||
pipeline.addLast("bytebuf2wsEncoder", new ByteBufToWebSocketFrameEncoder());
|
pipeline.addLast("bytebuf2wsEncoder", new ByteBufToWebSocketFrameEncoder());
|
||||||
pipeline.addFirst("idleStateHandler", new IdleStateHandler(0, 0, Constants.DEFAULT_CONNECT_TIMEOUT));
|
pipeline.addFirst("idleStateHandler", new IdleStateHandler(0, 0, nettyChannelTimeoutSeconds));
|
||||||
pipeline.addAfter("idleStateHandler", "idleEventHandler", timeoutHandler);
|
pipeline.addAfter("idleStateHandler", "idleEventHandler", timeoutHandler);
|
||||||
pipeline.addFirst("bytemetrics", new BytesMetricsHandler(m_bytesMetricsCollector));
|
pipeline.addFirst("bytemetrics", new BytesMetricsHandler(m_bytesMetricsCollector));
|
||||||
pipeline.addLast("decoder", new MQTTDecoder());
|
pipeline.addLast("decoder", new MQTTDecoder());
|
||||||
|
|||||||
Reference in New Issue
Block a user