提交 c36f09aa 编写于 作者: C chengxiangwang

1.add mqttServerConfig/mqttClientConfig 2.delete payload from RemotingCommand

上级 bd21a92d
...@@ -16,32 +16,32 @@ ...@@ -16,32 +16,32 @@
*/ */
package org.apache.rocketmq.common; package org.apache.rocketmq.common;
import java.net.InetAddress;
import java.net.UnknownHostException;
import org.apache.rocketmq.common.annotation.ImportantField; import org.apache.rocketmq.common.annotation.ImportantField;
import org.apache.rocketmq.common.constant.LoggerName; import org.apache.rocketmq.common.constant.LoggerName;
import org.apache.rocketmq.logging.InternalLogger; import org.apache.rocketmq.logging.InternalLogger;
import org.apache.rocketmq.logging.InternalLoggerFactory; import org.apache.rocketmq.logging.InternalLoggerFactory;
import org.apache.rocketmq.remoting.ClientConfig;
import org.apache.rocketmq.remoting.ServerConfig;
public class MqttConfig { public class MqttConfig {
private static final InternalLogger log = InternalLoggerFactory.getLogger(LoggerName.SNODE_LOGGER_NAME); private static final InternalLogger log = InternalLoggerFactory.getLogger(LoggerName.SNODE_LOGGER_NAME);
private String rocketmqHome = System.getProperty(MixAll.ROCKETMQ_HOME_PROPERTY, System.getenv(MixAll.ROCKETMQ_HOME_ENV)); private ServerConfig mqttServerConfig;
private int snodeHandleMqttThreadPoolQueueCapacity = 10000; private ClientConfig mqttClientConfig;
private int snodeHandleMqttMessageMinPoolSize = 10; private int handleMqttThreadPoolQueueCapacity = 10000;
private int snodeHandleMqttMessageMaxPoolSize = 20; private int handleMqttMessageMinPoolSize = 10;
private long houseKeepingInterval = 10 * 1000; private int handleMqttMessageMaxPoolSize = 20;
private int snodePushMqttMessageMinPoolSize = 10; private int pushMqttMessageMinPoolSize = 10;
private int snodePushMqttMessageMaxPoolSize = 20; private int pushMqttMessageMaxPoolSize = 20;
private int snodePushMqttMessageThreadPoolQueueCapacity = 10000; private int pushMqttMessageThreadPoolQueueCapacity = 10000;
private int listenPort = 1883; private int listenPort = 1883;
/** /**
...@@ -50,119 +50,84 @@ public class MqttConfig { ...@@ -50,119 +50,84 @@ public class MqttConfig {
@ImportantField @ImportantField
private boolean aclEnable = false; private boolean aclEnable = false;
public long getHouseKeepingInterval() { public int getListenPort() {
return houseKeepingInterval; return listenPort;
}
public void setHouseKeepingInterval(long houseKeepingInterval) {
this.houseKeepingInterval = houseKeepingInterval;
}
/**
* This configurable item defines interval of topics registration of broker to name server. Allowing values are
* between 10, 000 and 60, 000 milliseconds.
*/
private int registerNameServerPeriod = 1000 * 30;
public int getRegisterNameServerPeriod() {
return registerNameServerPeriod;
}
public void setRegisterNameServerPeriod(int registerNameServerPeriod) {
this.registerNameServerPeriod = registerNameServerPeriod;
}
@ImportantField
private boolean fetchNamesrvAddrByAddressServer = false;
public static String localHostName() {
try {
return InetAddress.getLocalHost().getHostName();
} catch (UnknownHostException e) {
log.error("Failed to obtain the host name", e);
}
return "DEFAULT_SNODE";
} }
public boolean isFetchNamesrvAddrByAddressServer() { public void setListenPort(int listenPort) {
return fetchNamesrvAddrByAddressServer; this.listenPort = listenPort;
} }
public void setFetchNamesrvAddrByAddressServer(boolean fetchNamesrvAddrByAddressServer) {
this.fetchNamesrvAddrByAddressServer = fetchNamesrvAddrByAddressServer;
}
public int getListenPort() { public boolean isAclEnable() {
return listenPort; return aclEnable;
} }
public String getRocketmqHome() { public void setAclEnable(boolean aclEnable) {
return rocketmqHome; this.aclEnable = aclEnable;
} }
public void setRocketmqHome(String rocketmqHome) { public ServerConfig getMqttServerConfig() {
this.rocketmqHome = rocketmqHome; return mqttServerConfig;
} }
public void setListenPort(int listenPort) { public void setMqttServerConfig(ServerConfig mqttServerConfig) {
this.listenPort = listenPort; this.mqttServerConfig = mqttServerConfig;
} }
public int getSnodeHandleMqttThreadPoolQueueCapacity() { public ClientConfig getMqttClientConfig() {
return snodeHandleMqttThreadPoolQueueCapacity; return mqttClientConfig;
} }
public void setSnodeHandleMqttThreadPoolQueueCapacity(int snodeHandleMqttThreadPoolQueueCapacity) { public void setMqttClientConfig(ClientConfig mqttClientConfig) {
this.snodeHandleMqttThreadPoolQueueCapacity = snodeHandleMqttThreadPoolQueueCapacity; this.mqttClientConfig = mqttClientConfig;
} }
public int getSnodeHandleMqttMessageMinPoolSize() { public int getHandleMqttThreadPoolQueueCapacity() {
return snodeHandleMqttMessageMinPoolSize; return handleMqttThreadPoolQueueCapacity;
} }
public void setSnodeHandleMqttMessageMinPoolSize(int snodeHandleMqttMessageMinPoolSize) { public void setHandleMqttThreadPoolQueueCapacity(int handleMqttThreadPoolQueueCapacity) {
this.snodeHandleMqttMessageMinPoolSize = snodeHandleMqttMessageMinPoolSize; this.handleMqttThreadPoolQueueCapacity = handleMqttThreadPoolQueueCapacity;
} }
public int getSnodeHandleMqttMessageMaxPoolSize() { public int getHandleMqttMessageMinPoolSize() {
return snodeHandleMqttMessageMaxPoolSize; return handleMqttMessageMinPoolSize;
} }
public void setSnodeHandleMqttMessageMaxPoolSize(int snodeHandleMqttMessageMaxPoolSize) { public void setHandleMqttMessageMinPoolSize(int handleMqttMessageMinPoolSize) {
this.snodeHandleMqttMessageMaxPoolSize = snodeHandleMqttMessageMaxPoolSize; this.handleMqttMessageMinPoolSize = handleMqttMessageMinPoolSize;
} }
public int getSnodePushMqttMessageMinPoolSize() { public int getHandleMqttMessageMaxPoolSize() {
return snodePushMqttMessageMinPoolSize; return handleMqttMessageMaxPoolSize;
} }
public void setSnodePushMqttMessageMinPoolSize(int snodePushMqttMessageMinPoolSize) { public void setHandleMqttMessageMaxPoolSize(int handleMqttMessageMaxPoolSize) {
this.snodePushMqttMessageMinPoolSize = snodePushMqttMessageMinPoolSize; this.handleMqttMessageMaxPoolSize = handleMqttMessageMaxPoolSize;
} }
public int getSnodePushMqttMessageMaxPoolSize() { public int getPushMqttMessageMinPoolSize() {
return snodePushMqttMessageMaxPoolSize; return pushMqttMessageMinPoolSize;
} }
public void setSnodePushMqttMessageMaxPoolSize(int snodePushMqttMessageMaxPoolSize) { public void setPushMqttMessageMinPoolSize(int pushMqttMessageMinPoolSize) {
this.snodePushMqttMessageMaxPoolSize = snodePushMqttMessageMaxPoolSize; this.pushMqttMessageMinPoolSize = pushMqttMessageMinPoolSize;
} }
public int getSnodePushMqttMessageThreadPoolQueueCapacity() { public int getPushMqttMessageMaxPoolSize() {
return snodePushMqttMessageThreadPoolQueueCapacity; return pushMqttMessageMaxPoolSize;
} }
public void setSnodePushMqttMessageThreadPoolQueueCapacity(int snodePushMqttMessageThreadPoolQueueCapacity) { public void setPushMqttMessageMaxPoolSize(int pushMqttMessageMaxPoolSize) {
this.snodePushMqttMessageThreadPoolQueueCapacity = snodePushMqttMessageThreadPoolQueueCapacity; this.pushMqttMessageMaxPoolSize = pushMqttMessageMaxPoolSize;
} }
public boolean isAclEnable() { public int getPushMqttMessageThreadPoolQueueCapacity() {
return aclEnable; return pushMqttMessageThreadPoolQueueCapacity;
} }
public void setAclEnable(boolean aclEnable) { public void setPushMqttMessageThreadPoolQueueCapacity(int pushMqttMessageThreadPoolQueueCapacity) {
this.aclEnable = aclEnable; this.pushMqttMessageThreadPoolQueueCapacity = pushMqttMessageThreadPoolQueueCapacity;
} }
} }
...@@ -60,12 +60,6 @@ public class SnodeConfig { ...@@ -60,12 +60,6 @@ public class SnodeConfig {
private int snodeSendMessageMaxPoolSize = 20; private int snodeSendMessageMaxPoolSize = 20;
private int snodeHandleMqttThreadPoolQueueCapacity = 10000;
private int snodeHandleMqttMessageMinPoolSize = 10;
private int snodeHandleMqttMessageMaxPoolSize = 20;
private int snodeHeartBeatCorePoolSize = 1; private int snodeHeartBeatCorePoolSize = 1;
private int snodeHeartBeatMaxPoolSize = 2; private int snodeHeartBeatMaxPoolSize = 2;
...@@ -88,12 +82,6 @@ public class SnodeConfig { ...@@ -88,12 +82,6 @@ public class SnodeConfig {
private int snodePushMessageThreadPoolQueueCapacity = 10000; private int snodePushMessageThreadPoolQueueCapacity = 10000;
private int snodePushMqttMessageMinPoolSize = 10;
private int snodePushMqttMessageMaxPoolSize = 20;
private int snodePushMqttMessageThreadPoolQueueCapacity = 10000;
private int slowConsumerThreshold = 1024; private int slowConsumerThreshold = 1024;
private final String sendMessageInterceptorPath = "META-INF/service/org.apache.rocketmq.snode.interceptor.SendMessageInterceptor"; private final String sendMessageInterceptorPath = "META-INF/service/org.apache.rocketmq.snode.interceptor.SendMessageInterceptor";
...@@ -277,30 +265,6 @@ public class SnodeConfig { ...@@ -277,30 +265,6 @@ public class SnodeConfig {
this.snodeId = snodeId; this.snodeId = snodeId;
} }
public int getSnodeHandleMqttThreadPoolQueueCapacity() {
return snodeHandleMqttThreadPoolQueueCapacity;
}
public void setSnodeHandleMqttThreadPoolQueueCapacity(int snodeHandleMqttThreadPoolQueueCapacity) {
this.snodeHandleMqttThreadPoolQueueCapacity = snodeHandleMqttThreadPoolQueueCapacity;
}
public int getSnodeHandleMqttMessageMinPoolSize() {
return snodeHandleMqttMessageMinPoolSize;
}
public void setSnodeHandleMqttMessageMinPoolSize(int snodeHandleMqttMessageMinPoolSize) {
this.snodeHandleMqttMessageMinPoolSize = snodeHandleMqttMessageMinPoolSize;
}
public int getSnodeHandleMqttMessageMaxPoolSize() {
return snodeHandleMqttMessageMaxPoolSize;
}
public void setSnodeHandleMqttMessageMaxPoolSize(int snodeHandleMqttMessageMaxPoolSize) {
this.snodeHandleMqttMessageMaxPoolSize = snodeHandleMqttMessageMaxPoolSize;
}
public String getSnodeName() { public String getSnodeName() {
return snodeName; return snodeName;
} }
...@@ -365,30 +329,6 @@ public class SnodeConfig { ...@@ -365,30 +329,6 @@ public class SnodeConfig {
this.snodePushMessageThreadPoolQueueCapacity = snodePushMessageThreadPoolQueueCapacity; this.snodePushMessageThreadPoolQueueCapacity = snodePushMessageThreadPoolQueueCapacity;
} }
public int getSnodePushMqttMessageMinPoolSize() {
return snodePushMqttMessageMinPoolSize;
}
public void setSnodePushMqttMessageMinPoolSize(int snodePushMqttMessageMinPoolSize) {
this.snodePushMqttMessageMinPoolSize = snodePushMqttMessageMinPoolSize;
}
public int getSnodePushMqttMessageMaxPoolSize() {
return snodePushMqttMessageMaxPoolSize;
}
public void setSnodePushMqttMessageMaxPoolSize(int snodePushMqttMessageMaxPoolSize) {
this.snodePushMqttMessageMaxPoolSize = snodePushMqttMessageMaxPoolSize;
}
public int getSnodePushMqttMessageThreadPoolQueueCapacity() {
return snodePushMqttMessageThreadPoolQueueCapacity;
}
public void setSnodePushMqttMessageThreadPoolQueueCapacity(int snodePushMqttMessageThreadPoolQueueCapacity) {
this.snodePushMqttMessageThreadPoolQueueCapacity = snodePushMqttMessageThreadPoolQueueCapacity;
}
public String getSendMessageInterceptorPath() { public String getSendMessageInterceptorPath() {
return sendMessageInterceptorPath; return sendMessageInterceptorPath;
} }
......
...@@ -653,6 +653,11 @@ ...@@ -653,6 +653,11 @@
<artifactId>org.eclipse.paho.client.mqttv3</artifactId> <artifactId>org.eclipse.paho.client.mqttv3</artifactId>
<version>1.2.0</version> <version>1.2.0</version>
</dependency> </dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>LATEST</version>
</dependency>
</dependencies> </dependencies>
</dependencyManagement> </dependencyManagement>
</project> </project>
...@@ -15,7 +15,8 @@ ...@@ -15,7 +15,8 @@
limitations under the License. limitations under the License.
--> -->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent> <parent>
<groupId>org.apache.rocketmq</groupId> <groupId>org.apache.rocketmq</groupId>
<artifactId>rocketmq-all</artifactId> <artifactId>rocketmq-all</artifactId>
...@@ -38,8 +39,8 @@ ...@@ -38,8 +39,8 @@
<artifactId>fastjson</artifactId> <artifactId>fastjson</artifactId>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.msgpack</groupId> <groupId>org.msgpack</groupId>
<artifactId>msgpack</artifactId> <artifactId>msgpack</artifactId>
</dependency> </dependency>
<dependency> <dependency>
<groupId>io.netty</groupId> <groupId>io.netty</groupId>
...@@ -62,5 +63,9 @@ ...@@ -62,5 +63,9 @@
<groupId>com.google.guava</groupId> <groupId>com.google.guava</groupId>
<artifactId>guava</artifactId> <artifactId>guava</artifactId>
</dependency> </dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
</dependency>
</dependencies> </dependencies>
</project> </project>
...@@ -20,7 +20,6 @@ import org.apache.rocketmq.remoting.netty.NettySystemConfig; ...@@ -20,7 +20,6 @@ import org.apache.rocketmq.remoting.netty.NettySystemConfig;
public class ServerConfig implements Cloneable { public class ServerConfig implements Cloneable {
private int listenPort = 8888; private int listenPort = 8888;
private int mqttListenPort = 1883;
private int serverWorkerThreads = 8; private int serverWorkerThreads = 8;
private int serverCallbackExecutorThreads = 8; private int serverCallbackExecutorThreads = 8;
private int serverSelectorThreads = 3; private int serverSelectorThreads = 3;
...@@ -76,14 +75,6 @@ public class ServerConfig implements Cloneable { ...@@ -76,14 +75,6 @@ public class ServerConfig implements Cloneable {
this.listenPort = listenPort; this.listenPort = listenPort;
} }
public int getMqttListenPort() {
return mqttListenPort;
}
public void setMqttListenPort(int mqttListenPort) {
this.mqttListenPort = mqttListenPort;
}
public int getServerWorkerThreads() { public int getServerWorkerThreads() {
return serverWorkerThreads; return serverWorkerThreads;
} }
......
...@@ -80,8 +80,6 @@ public class RemotingCommand { ...@@ -80,8 +80,6 @@ public class RemotingCommand {
private transient byte[] body; private transient byte[] body;
private Object payload;
public RemotingCommand() { public RemotingCommand() {
} }
...@@ -261,14 +259,6 @@ public class RemotingCommand { ...@@ -261,14 +259,6 @@ public class RemotingCommand {
this.body = body; this.body = body;
} }
public Object getPayload() {
return payload;
}
public void setPayload(Object payload) {
this.payload = payload;
}
public HashMap<String, String> getExtFields() { public HashMap<String, String> getExtFields() {
return extFields; return extFields;
} }
......
...@@ -60,7 +60,7 @@ import org.apache.rocketmq.remoting.util.ThreadUtils; ...@@ -60,7 +60,7 @@ import org.apache.rocketmq.remoting.util.ThreadUtils;
public class MqttRemotingClient extends NettyRemotingClientAbstract implements RemotingClient { public class MqttRemotingClient extends NettyRemotingClientAbstract implements RemotingClient {
private static final InternalLogger log = InternalLoggerFactory.getLogger(RemotingHelper.ROCKETMQ_REMOTING); private static final InternalLogger log = InternalLoggerFactory.getLogger(RemotingHelper.ROCKETMQ_REMOTING);
private ClientConfig nettyClientConfig; private ClientConfig mqttClientConfig;
private Bootstrap bootstrap = new Bootstrap(); private Bootstrap bootstrap = new Bootstrap();
private EventLoopGroup eventLoopGroupWorker; private EventLoopGroup eventLoopGroupWorker;
...@@ -76,33 +76,38 @@ public class MqttRemotingClient extends NettyRemotingClientAbstract implements R ...@@ -76,33 +76,38 @@ public class MqttRemotingClient extends NettyRemotingClientAbstract implements R
public MqttRemotingClient() { public MqttRemotingClient() {
super(); super();
loadProperties();
} }
public MqttRemotingClient(final ClientConfig nettyClientConfig) { private void loadProperties() {
this(nettyClientConfig, null);
}
public MqttRemotingClient(final ClientConfig mqttClientConfig) {
this(mqttClientConfig, null);
} }
public MqttRemotingClient(final ClientConfig nettyClientConfig, public MqttRemotingClient(final ClientConfig mqttClientConfig,
final ChannelEventListener channelEventListener) { final ChannelEventListener channelEventListener) {
super(nettyClientConfig.getClientOnewaySemaphoreValue(), nettyClientConfig.getClientAsyncSemaphoreValue()); super(mqttClientConfig.getClientOnewaySemaphoreValue(), mqttClientConfig.getClientAsyncSemaphoreValue());
init(nettyClientConfig, channelEventListener); init(mqttClientConfig, channelEventListener);
} }
@Override @Override
public RemotingClient init(ClientConfig nettyClientConfig, ChannelEventListener channelEventListener) { public RemotingClient init(ClientConfig mqttClientConfig, ChannelEventListener channelEventListener) {
this.nettyClientConfig = nettyClientConfig; this.mqttClientConfig = mqttClientConfig;
this.channelEventListener = channelEventListener; this.channelEventListener = channelEventListener;
this.eventLoopGroupWorker = new NioEventLoopGroup(nettyClientConfig.getClientWorkerThreads(), ThreadUtils.newGenericThreadFactory("NettyClientEpollIoThreads", this.eventLoopGroupWorker = new NioEventLoopGroup(mqttClientConfig.getClientWorkerThreads(), ThreadUtils.newGenericThreadFactory("NettyClientEpollIoThreads",
nettyClientConfig.getClientWorkerThreads())); mqttClientConfig.getClientWorkerThreads()));
this.publicExecutor = ThreadUtils.newFixedThreadPool( this.publicExecutor = ThreadUtils.newFixedThreadPool(
nettyClientConfig.getClientCallbackExecutorThreads(), mqttClientConfig.getClientCallbackExecutorThreads(),
10000, "Remoting-PublicExecutor", true); 10000, "MqttRemoting-PublicExecutor", true);
this.defaultEventExecutorGroup = new DefaultEventExecutorGroup(nettyClientConfig.getClientWorkerThreads(), this.defaultEventExecutorGroup = new DefaultEventExecutorGroup(mqttClientConfig.getClientWorkerThreads(),
ThreadUtils.newGenericThreadFactory("NettyClientWorkerThreads", nettyClientConfig.getClientWorkerThreads())); ThreadUtils.newGenericThreadFactory("MqttNettyClientWorkerThreads", mqttClientConfig.getClientWorkerThreads()));
if (nettyClientConfig.isUseTLS()) { if (mqttClientConfig.isUseTLS()) {
try { try {
sslContext = TlsHelper.buildSslContext(true); sslContext = TlsHelper.buildSslContext(true);
log.info("SSL enabled for client"); log.info("SSL enabled for mqtt client");
} catch (IOException e) { } catch (IOException e) {
log.error("Failed to create SSLContext", e); log.error("Failed to create SSLContext", e);
} catch (CertificateException e) { } catch (CertificateException e) {
...@@ -123,14 +128,14 @@ public class MqttRemotingClient extends NettyRemotingClientAbstract implements R ...@@ -123,14 +128,14 @@ public class MqttRemotingClient extends NettyRemotingClientAbstract implements R
bootstrap = this.bootstrap.group(this.eventLoopGroupWorker).channel(NioSocketChannel.class) bootstrap = this.bootstrap.group(this.eventLoopGroupWorker).channel(NioSocketChannel.class)
.option(ChannelOption.TCP_NODELAY, true) .option(ChannelOption.TCP_NODELAY, true)
.option(ChannelOption.SO_KEEPALIVE, false) .option(ChannelOption.SO_KEEPALIVE, false)
.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, nettyClientConfig.getConnectTimeoutMillis()) .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, mqttClientConfig.getConnectTimeoutMillis())
.option(ChannelOption.SO_SNDBUF, nettyClientConfig.getClientSocketSndBufSize()) .option(ChannelOption.SO_SNDBUF, mqttClientConfig.getClientSocketSndBufSize())
.option(ChannelOption.SO_RCVBUF, nettyClientConfig.getClientSocketRcvBufSize()) .option(ChannelOption.SO_RCVBUF, mqttClientConfig.getClientSocketRcvBufSize())
.handler(new ChannelInitializer<SocketChannel>() { .handler(new ChannelInitializer<SocketChannel>() {
@Override @Override
public void initChannel(SocketChannel ch) { public void initChannel(SocketChannel ch) {
ChannelPipeline pipeline = ch.pipeline(); ChannelPipeline pipeline = ch.pipeline();
if (nettyClientConfig.isUseTLS()) { if (mqttClientConfig.isUseTLS()) {
if (null != sslContext) { if (null != sslContext) {
pipeline.addFirst(defaultEventExecutorGroup, "sslHandler", sslContext.newHandler(ch.alloc())); pipeline.addFirst(defaultEventExecutorGroup, "sslHandler", sslContext.newHandler(ch.alloc()));
log.info("Prepend SSL handler"); log.info("Prepend SSL handler");
...@@ -142,7 +147,7 @@ public class MqttRemotingClient extends NettyRemotingClientAbstract implements R ...@@ -142,7 +147,7 @@ public class MqttRemotingClient extends NettyRemotingClientAbstract implements R
defaultEventExecutorGroup, defaultEventExecutorGroup,
MqttEncoder.INSTANCE, MqttEncoder.INSTANCE,
new MqttDecoder(), new MqttDecoder(),
new IdleStateHandler(0, 0, nettyClientConfig.getClientChannelMaxIdleTimeSeconds()), new IdleStateHandler(0, 0, mqttClientConfig.getClientChannelMaxIdleTimeSeconds()),
new NettyConnectManageHandler(), new NettyConnectManageHandler(),
new NettyClientHandler()); new NettyClientHandler());
} }
...@@ -199,7 +204,7 @@ public class MqttRemotingClient extends NettyRemotingClientAbstract implements R ...@@ -199,7 +204,7 @@ public class MqttRemotingClient extends NettyRemotingClientAbstract implements R
throw (RemotingSendRequestException) remotingException; throw (RemotingSendRequestException) remotingException;
} }
if (remotingException instanceof RemotingTimeoutException) { if (remotingException instanceof RemotingTimeoutException) {
if (nettyClientConfig.isClientCloseSocketIfTimeout()) { if (mqttClientConfig.isClientCloseSocketIfTimeout()) {
this.closeRemotingChannel(addr, remotingChannel); this.closeRemotingChannel(addr, remotingChannel);
log.warn("InvokeSync: close socket because of timeout, {}ms, {}", timeoutMillis, addr); log.warn("InvokeSync: close socket because of timeout, {}ms, {}", timeoutMillis, addr);
} }
......
...@@ -71,7 +71,7 @@ public class MqttRemotingServer extends NettyRemotingServerAbstract implements R ...@@ -71,7 +71,7 @@ public class MqttRemotingServer extends NettyRemotingServerAbstract implements R
private ServerBootstrap serverBootstrap; private ServerBootstrap serverBootstrap;
private EventLoopGroup eventLoopGroupSelector; private EventLoopGroup eventLoopGroupSelector;
private EventLoopGroup eventLoopGroupBoss; private EventLoopGroup eventLoopGroupBoss;
private ServerConfig nettyServerConfig; private ServerConfig mqttServerConfig;
private ExecutorService publicExecutor; private ExecutorService publicExecutor;
private ChannelEventListener channelEventListener; private ChannelEventListener channelEventListener;
...@@ -89,32 +89,32 @@ public class MqttRemotingServer extends NettyRemotingServerAbstract implements R ...@@ -89,32 +89,32 @@ public class MqttRemotingServer extends NettyRemotingServerAbstract implements R
super(); super();
} }
public MqttRemotingServer(final ServerConfig nettyServerConfig) { public MqttRemotingServer(final ServerConfig mqttServerConfig) {
this(nettyServerConfig, null); this(mqttServerConfig, null);
} }
public MqttRemotingServer(final ServerConfig nettyServerConfig, public MqttRemotingServer(final ServerConfig mqttServerConfig,
final ChannelEventListener channelEventListener) { final ChannelEventListener channelEventListener) {
init(nettyServerConfig, channelEventListener); init(mqttServerConfig, channelEventListener);
} }
@Override @Override
public RemotingServer init(ServerConfig serverConfig, public RemotingServer init(ServerConfig serverConfig,
ChannelEventListener channelEventListener) { ChannelEventListener channelEventListener) {
this.nettyServerConfig = serverConfig; this.mqttServerConfig = serverConfig;
super.init(nettyServerConfig.getServerOnewaySemaphoreValue(), super.init(mqttServerConfig.getServerOnewaySemaphoreValue(),
nettyServerConfig.getServerAsyncSemaphoreValue()); mqttServerConfig.getServerAsyncSemaphoreValue());
this.serverBootstrap = new ServerBootstrap(); this.serverBootstrap = new ServerBootstrap();
this.channelEventListener = channelEventListener; this.channelEventListener = channelEventListener;
int publicThreadNums = nettyServerConfig.getServerCallbackExecutorThreads(); int publicThreadNums = mqttServerConfig.getServerCallbackExecutorThreads();
if (publicThreadNums <= 0) { if (publicThreadNums <= 0) {
publicThreadNums = 4; publicThreadNums = 4;
} }
this.publicExecutor = ThreadUtils.newFixedThreadPool( this.publicExecutor = ThreadUtils.newFixedThreadPool(
publicThreadNums, publicThreadNums,
10000, "MqttRemoting-PublicExecutor", true); 10000, "MqttRemoting-PublicExecutor", true);
if (JvmUtils.isUseEpoll() && this.nettyServerConfig.isUseEpollNativeSelector()) { if (JvmUtils.isUseEpoll() && this.mqttServerConfig.isUseEpollNativeSelector()) {
this.eventLoopGroupSelector = new EpollEventLoopGroup( this.eventLoopGroupSelector = new EpollEventLoopGroup(
serverConfig.getServerSelectorThreads(), serverConfig.getServerSelectorThreads(),
ThreadUtils.newGenericThreadFactory("MqttNettyEpollIoThreads", ThreadUtils.newGenericThreadFactory("MqttNettyEpollIoThreads",
...@@ -134,7 +134,7 @@ public class MqttRemotingServer extends NettyRemotingServerAbstract implements R ...@@ -134,7 +134,7 @@ public class MqttRemotingServer extends NettyRemotingServerAbstract implements R
serverConfig.getServerSelectorThreads())); serverConfig.getServerSelectorThreads()));
this.socketChannelClass = NioServerSocketChannel.class; this.socketChannelClass = NioServerSocketChannel.class;
} }
this.port = nettyServerConfig.getMqttListenPort(); this.port = mqttServerConfig.getListenPort();
this.defaultEventExecutorGroup = new DefaultEventExecutorGroup( this.defaultEventExecutorGroup = new DefaultEventExecutorGroup(
serverConfig.getServerWorkerThreads(), serverConfig.getServerWorkerThreads(),
ThreadUtils.newGenericThreadFactory("MqttNettyWorkerThreads", ThreadUtils.newGenericThreadFactory("MqttNettyWorkerThreads",
...@@ -169,9 +169,9 @@ public class MqttRemotingServer extends NettyRemotingServerAbstract implements R ...@@ -169,9 +169,9 @@ public class MqttRemotingServer extends NettyRemotingServerAbstract implements R
.option(ChannelOption.SO_KEEPALIVE, false) .option(ChannelOption.SO_KEEPALIVE, false)
.childOption(ChannelOption.TCP_NODELAY, true) .childOption(ChannelOption.TCP_NODELAY, true)
.childOption(ChannelOption.SO_SNDBUF, .childOption(ChannelOption.SO_SNDBUF,
nettyServerConfig.getServerSocketSndBufSize()) mqttServerConfig.getServerSocketSndBufSize())
.childOption(ChannelOption.SO_RCVBUF, .childOption(ChannelOption.SO_RCVBUF,
nettyServerConfig.getServerSocketRcvBufSize()) mqttServerConfig.getServerSocketRcvBufSize())
.localAddress(new InetSocketAddress(this.port)) .localAddress(new InetSocketAddress(this.port))
.childHandler(new ChannelInitializer<SocketChannel>() { .childHandler(new ChannelInitializer<SocketChannel>() {
@Override @Override
...@@ -184,11 +184,11 @@ public class MqttRemotingServer extends NettyRemotingServerAbstract implements R ...@@ -184,11 +184,11 @@ public class MqttRemotingServer extends NettyRemotingServerAbstract implements R
MqttEncoder.INSTANCE, MqttEncoder.INSTANCE,
new MqttMessage2RemotingCommandHandler(), new MqttMessage2RemotingCommandHandler(),
new RemotingCommand2MqttMessageHandler(), new RemotingCommand2MqttMessageHandler(),
new IdleStateHandler(nettyServerConfig new IdleStateHandler(mqttServerConfig
.getConnectionChannelReaderIdleSeconds(), .getConnectionChannelReaderIdleSeconds(),
nettyServerConfig mqttServerConfig
.getConnectionChannelWriterIdleSeconds(), .getConnectionChannelWriterIdleSeconds(),
nettyServerConfig mqttServerConfig
.getServerChannelMaxIdleTimeSeconds()), .getServerChannelMaxIdleTimeSeconds()),
new NettyConnectManageHandler(), new NettyConnectManageHandler(),
new NettyServerHandler() new NettyServerHandler()
...@@ -197,7 +197,7 @@ public class MqttRemotingServer extends NettyRemotingServerAbstract implements R ...@@ -197,7 +197,7 @@ public class MqttRemotingServer extends NettyRemotingServerAbstract implements R
} }
}); });
if (nettyServerConfig.isServerPooledByteBufAllocatorEnable()) { if (mqttServerConfig.isServerPooledByteBufAllocatorEnable()) {
childHandler.childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT); childHandler.childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT);
} }
......
...@@ -45,5 +45,4 @@ public class EncodeDecodeDispatcher { ...@@ -45,5 +45,4 @@ public class EncodeDecodeDispatcher {
public static Map<MqttMessageType, Message2MessageEncodeDecode> getEncodeDecodeDispatcher() { public static Map<MqttMessageType, Message2MessageEncodeDecode> getEncodeDecodeDispatcher() {
return encodeDecodeDispatcher; return encodeDecodeDispatcher;
} }
} }
...@@ -23,6 +23,7 @@ import io.netty.handler.codec.mqtt.MqttFixedHeader; ...@@ -23,6 +23,7 @@ import io.netty.handler.codec.mqtt.MqttFixedHeader;
import io.netty.handler.codec.mqtt.MqttMessage; import io.netty.handler.codec.mqtt.MqttMessage;
import org.apache.rocketmq.remoting.protocol.RemotingCommand; import org.apache.rocketmq.remoting.protocol.RemotingCommand;
import org.apache.rocketmq.remoting.transport.mqtt.MqttHeader; import org.apache.rocketmq.remoting.transport.mqtt.MqttHeader;
import org.apache.rocketmq.remoting.util.MqttEncodeDecodeUtil;
public class MqttConnectEncodeDecode implements Message2MessageEncodeDecode { public class MqttConnectEncodeDecode implements Message2MessageEncodeDecode {
...@@ -53,7 +54,7 @@ public class MqttConnectEncodeDecode implements Message2MessageEncodeDecode { ...@@ -53,7 +54,7 @@ public class MqttConnectEncodeDecode implements Message2MessageEncodeDecode {
requestCommand = RemotingCommand requestCommand = RemotingCommand
.createRequestCommand(1000, mqttHeader); .createRequestCommand(1000, mqttHeader);
requestCommand.setPayload(((MqttConnectMessage) mqttMessage).payload()); requestCommand.setBody(MqttEncodeDecodeUtil.encode(((MqttConnectMessage) mqttMessage).payload()));
return requestCommand; return requestCommand;
} }
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
package org.apache.rocketmq.remoting.transport.mqtt.dispatcher; package org.apache.rocketmq.remoting.transport.mqtt.dispatcher;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.handler.codec.mqtt.MqttFixedHeader; import io.netty.handler.codec.mqtt.MqttFixedHeader;
import io.netty.handler.codec.mqtt.MqttMessage; import io.netty.handler.codec.mqtt.MqttMessage;
import io.netty.handler.codec.mqtt.MqttMessageType; import io.netty.handler.codec.mqtt.MqttMessageType;
...@@ -48,9 +49,12 @@ public class MqttPublishEncodeDecode implements Message2MessageEncodeDecode { ...@@ -48,9 +49,12 @@ public class MqttPublishEncodeDecode implements Message2MessageEncodeDecode {
requestCommand = RemotingCommand requestCommand = RemotingCommand
.createRequestCommand(1000, mqttHeader); .createRequestCommand(1000, mqttHeader);
//invoke copy to generate a new ByteBuf or increase refCnt by 1 by invoking retain() method, because release method is invoked in Message2MessageEncodeDecode.channelRead ByteBuf payload = ((MqttPublishMessage) mqttMessage).payload();
requestCommand.setPayload(((MqttPublishMessage) mqttMessage).payload().copy()); byte[] body = new byte[payload.readableBytes()];
payload.readBytes(body);
requestCommand.setBody(body);
return requestCommand; return requestCommand;
} }
@Override @Override
...@@ -60,6 +64,6 @@ public class MqttPublishEncodeDecode implements Message2MessageEncodeDecode { ...@@ -60,6 +64,6 @@ public class MqttPublishEncodeDecode implements Message2MessageEncodeDecode {
new MqttFixedHeader(MqttMessageType.PUBLISH, mqttHeader.isDup(), new MqttFixedHeader(MqttMessageType.PUBLISH, mqttHeader.isDup(),
MqttQoS.valueOf(mqttHeader.getQosLevel()), mqttHeader.isRetain(), MqttQoS.valueOf(mqttHeader.getQosLevel()), mqttHeader.isRetain(),
mqttHeader.getRemainingLength()), mqttHeader.getRemainingLength()),
new MqttPublishVariableHeader(mqttHeader.getTopicName(), mqttHeader.getPacketId()), (ByteBuf) remotingCommand.getPayload()); new MqttPublishVariableHeader(mqttHeader.getTopicName(), mqttHeader.getPacketId()), Unpooled.copiedBuffer(remotingCommand.getBody()));
} }
} }
...@@ -28,6 +28,7 @@ import java.io.UnsupportedEncodingException; ...@@ -28,6 +28,7 @@ import java.io.UnsupportedEncodingException;
import org.apache.rocketmq.remoting.exception.RemotingCommandException; import org.apache.rocketmq.remoting.exception.RemotingCommandException;
import org.apache.rocketmq.remoting.protocol.RemotingCommand; import org.apache.rocketmq.remoting.protocol.RemotingCommand;
import org.apache.rocketmq.remoting.transport.mqtt.MqttHeader; import org.apache.rocketmq.remoting.transport.mqtt.MqttHeader;
import org.apache.rocketmq.remoting.util.MqttEncodeDecodeUtil;
public class MqttSubackEncodeDecode implements Message2MessageEncodeDecode { public class MqttSubackEncodeDecode implements Message2MessageEncodeDecode {
...@@ -43,6 +44,6 @@ public class MqttSubackEncodeDecode implements Message2MessageEncodeDecode { ...@@ -43,6 +44,6 @@ public class MqttSubackEncodeDecode implements Message2MessageEncodeDecode {
new MqttFixedHeader(MqttMessageType.SUBACK, mqttHeader.isDup(), new MqttFixedHeader(MqttMessageType.SUBACK, mqttHeader.isDup(),
MqttQoS.valueOf(mqttHeader.getQosLevel()), mqttHeader.isRetain(), MqttQoS.valueOf(mqttHeader.getQosLevel()), mqttHeader.isRetain(),
mqttHeader.getRemainingLength()), mqttHeader.getRemainingLength()),
MqttMessageIdVariableHeader.from(mqttHeader.getMessageId()), (MqttSubAckPayload) remotingCommand.getPayload()); MqttMessageIdVariableHeader.from(mqttHeader.getMessageId()), (MqttSubAckPayload) MqttEncodeDecodeUtil.decode(remotingCommand.getBody(),MqttSubAckPayload.class));
} }
} }
...@@ -23,6 +23,7 @@ import io.netty.handler.codec.mqtt.MqttMessageIdVariableHeader; ...@@ -23,6 +23,7 @@ import io.netty.handler.codec.mqtt.MqttMessageIdVariableHeader;
import io.netty.handler.codec.mqtt.MqttSubscribeMessage; import io.netty.handler.codec.mqtt.MqttSubscribeMessage;
import org.apache.rocketmq.remoting.protocol.RemotingCommand; import org.apache.rocketmq.remoting.protocol.RemotingCommand;
import org.apache.rocketmq.remoting.transport.mqtt.MqttHeader; import org.apache.rocketmq.remoting.transport.mqtt.MqttHeader;
import org.apache.rocketmq.remoting.util.MqttEncodeDecodeUtil;
public class MqttSubscribeEncodeDecode implements Message2MessageEncodeDecode { public class MqttSubscribeEncodeDecode implements Message2MessageEncodeDecode {
...@@ -44,7 +45,7 @@ public class MqttSubscribeEncodeDecode implements Message2MessageEncodeDecode { ...@@ -44,7 +45,7 @@ public class MqttSubscribeEncodeDecode implements Message2MessageEncodeDecode {
requestCommand = RemotingCommand requestCommand = RemotingCommand
.createRequestCommand(1000, mqttHeader); .createRequestCommand(1000, mqttHeader);
requestCommand.setPayload(((MqttSubscribeMessage) mqttMessage).payload()); requestCommand.setBody(MqttEncodeDecodeUtil.encode(((MqttSubscribeMessage) mqttMessage).payload()));
return requestCommand; return requestCommand;
} }
......
...@@ -23,6 +23,7 @@ import io.netty.handler.codec.mqtt.MqttMessageIdVariableHeader; ...@@ -23,6 +23,7 @@ import io.netty.handler.codec.mqtt.MqttMessageIdVariableHeader;
import io.netty.handler.codec.mqtt.MqttUnsubscribeMessage; import io.netty.handler.codec.mqtt.MqttUnsubscribeMessage;
import org.apache.rocketmq.remoting.protocol.RemotingCommand; import org.apache.rocketmq.remoting.protocol.RemotingCommand;
import org.apache.rocketmq.remoting.transport.mqtt.MqttHeader; import org.apache.rocketmq.remoting.transport.mqtt.MqttHeader;
import org.apache.rocketmq.remoting.util.MqttEncodeDecodeUtil;
public class MqttUnSubscribeEncodeDecode implements Message2MessageEncodeDecode { public class MqttUnSubscribeEncodeDecode implements Message2MessageEncodeDecode {
...@@ -42,7 +43,7 @@ public class MqttUnSubscribeEncodeDecode implements Message2MessageEncodeDecode ...@@ -42,7 +43,7 @@ public class MqttUnSubscribeEncodeDecode implements Message2MessageEncodeDecode
mqttHeader.setMessageId(variableHeader.messageId()); mqttHeader.setMessageId(variableHeader.messageId());
requestCommand = RemotingCommand.createRequestCommand(1000, mqttHeader); requestCommand = RemotingCommand.createRequestCommand(1000, mqttHeader);
requestCommand.setPayload(((MqttUnsubscribeMessage) mqttMessage).payload()); requestCommand.setBody(MqttEncodeDecodeUtil.encode(((MqttUnsubscribeMessage) mqttMessage).payload()));
return requestCommand; return requestCommand;
} }
......
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.rocketmq.remoting.util;
import com.google.gson.Gson;
import java.nio.charset.Charset;
public class MqttEncodeDecodeUtil {
private static final Gson GSON = new Gson();
public static byte[] encode(Object object) {
final String json = GSON.toJson(object);
if (json != null) {
return json.getBytes(Charset.forName("UTF-8"));
}
return null;
}
public static <T> Object decode(byte[] body, Class<T> classOfT) {
final String json = new String(body, Charset.forName("UTF-8"));
return GSON.fromJson(json, classOfT);
}
}
...@@ -24,6 +24,7 @@ import java.util.concurrent.ScheduledExecutorService; ...@@ -24,6 +24,7 @@ import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import org.apache.rocketmq.acl.AccessValidator; import org.apache.rocketmq.acl.AccessValidator;
import org.apache.rocketmq.broker.BrokerStartup; import org.apache.rocketmq.broker.BrokerStartup;
import org.apache.rocketmq.common.MqttConfig;
import org.apache.rocketmq.common.SnodeConfig; import org.apache.rocketmq.common.SnodeConfig;
import org.apache.rocketmq.common.ThreadFactoryImpl; import org.apache.rocketmq.common.ThreadFactoryImpl;
import org.apache.rocketmq.common.constant.LoggerName; import org.apache.rocketmq.common.constant.LoggerName;
...@@ -85,8 +86,11 @@ public class SnodeController { ...@@ -85,8 +86,11 @@ public class SnodeController {
.getLogger(LoggerName.SNODE_LOGGER_NAME); .getLogger(LoggerName.SNODE_LOGGER_NAME);
private final SnodeConfig snodeConfig; private final SnodeConfig snodeConfig;
private final MqttConfig mqttConfig;
private final ServerConfig nettyServerConfig; private final ServerConfig nettyServerConfig;
private final ClientConfig nettyClientConfig; private final ClientConfig nettyClientConfig;
private final ServerConfig mqttServerConfig;
private final ClientConfig mqttClientConfig;
private RemotingClient remotingClient; private RemotingClient remotingClient;
private RemotingServer snodeServer; private RemotingServer snodeServer;
private RemotingClient mqttRemotingClient; private RemotingClient mqttRemotingClient;
...@@ -125,12 +129,13 @@ public class SnodeController { ...@@ -125,12 +129,13 @@ public class SnodeController {
.newSingleThreadScheduledExecutor(new ThreadFactoryImpl( .newSingleThreadScheduledExecutor(new ThreadFactoryImpl(
"SnodeControllerScheduledThread")); "SnodeControllerScheduledThread"));
public SnodeController(ServerConfig nettyServerConfig, public SnodeController(SnodeConfig snodeConfig, MqttConfig mqttConfig) {
ClientConfig nettyClientConfig, this.nettyClientConfig = snodeConfig.getNettyClientConfig();
SnodeConfig snodeConfig) { this.nettyServerConfig = snodeConfig.getNettyServerConfig();
this.nettyClientConfig = nettyClientConfig; this.mqttServerConfig = mqttConfig.getMqttServerConfig();
this.nettyServerConfig = nettyServerConfig; this.mqttClientConfig = mqttConfig.getMqttClientConfig();
this.snodeConfig = snodeConfig; this.snodeConfig = snodeConfig;
this.mqttConfig = mqttConfig;
if (!this.snodeConfig.isEmbeddedModeEnable()) { if (!this.snodeConfig.isEmbeddedModeEnable()) {
this.enodeService = new RemoteEnodeServiceImpl(this); this.enodeService = new RemoteEnodeServiceImpl(this);
} else { } else {
...@@ -144,8 +149,9 @@ public class SnodeController { ...@@ -144,8 +149,9 @@ public class SnodeController {
} }
this.mqttRemotingClient = RemotingClientFactory.getInstance() this.mqttRemotingClient = RemotingClientFactory.getInstance()
.createRemotingClient(RemotingUtil.MQTT_PROTOCOL); .createRemotingClient(RemotingUtil.MQTT_PROTOCOL);
if (this.mqttRemotingClient != null) { if (this.mqttRemotingClient != null) {
this.mqttRemotingClient.init(this.getNettyClientConfig(), null); this.mqttRemotingClient.init(this.mqttClientConfig, null);
} }
this.sendMessageExecutor = ThreadUtils.newThreadPoolExecutor( this.sendMessageExecutor = ThreadUtils.newThreadPoolExecutor(
...@@ -185,12 +191,12 @@ public class SnodeController { ...@@ -185,12 +191,12 @@ public class SnodeController {
false); false);
this.handleMqttMessageExecutor = ThreadUtils.newThreadPoolExecutor( this.handleMqttMessageExecutor = ThreadUtils.newThreadPoolExecutor(
snodeConfig.getSnodeHandleMqttMessageMinPoolSize(), mqttConfig.getHandleMqttMessageMinPoolSize(),
snodeConfig.getSnodeHandleMqttMessageMaxPoolSize(), mqttConfig.getHandleMqttMessageMaxPoolSize(),
3000, 3000,
TimeUnit.MILLISECONDS, TimeUnit.MILLISECONDS,
new ArrayBlockingQueue<>(snodeConfig.getSnodeHandleMqttThreadPoolQueueCapacity()), new ArrayBlockingQueue<>(mqttConfig.getHandleMqttThreadPoolQueueCapacity()),
"SnodeHandleMqttMessageThread", "handleMqttMessageThread",
false); false);
if (this.snodeConfig.getNamesrvAddr() != null) { if (this.snodeConfig.getNamesrvAddr() != null) {
...@@ -224,6 +230,10 @@ public class SnodeController { ...@@ -224,6 +230,10 @@ public class SnodeController {
return snodeConfig; return snodeConfig;
} }
public MqttConfig getMqttConfig() {
return mqttConfig;
}
private void initRemotingServerInterceptorGroup() { private void initRemotingServerInterceptorGroup() {
List<Interceptor> remotingServerInterceptors = InterceptorFactory.getInstance() List<Interceptor> remotingServerInterceptors = InterceptorFactory.getInstance()
.loadInterceptors(this.snodeConfig.getRemotingServerInterceptorPath()); .loadInterceptors(this.snodeConfig.getRemotingServerInterceptorPath());
...@@ -251,7 +261,7 @@ public class SnodeController { ...@@ -251,7 +261,7 @@ public class SnodeController {
this.mqttRemotingServer = RemotingServerFactory.getInstance().createRemotingServer( this.mqttRemotingServer = RemotingServerFactory.getInstance().createRemotingServer(
RemotingUtil.MQTT_PROTOCOL); RemotingUtil.MQTT_PROTOCOL);
if (this.mqttRemotingServer != null) { if (this.mqttRemotingServer != null) {
this.mqttRemotingServer.init(this.nettyServerConfig, this.clientHousekeepingService); this.mqttRemotingServer.init(this.mqttServerConfig, this.clientHousekeepingService);
this.mqttRemotingServer.registerInterceptorGroup(this.remotingServerInterceptorGroup); this.mqttRemotingServer.registerInterceptorGroup(this.remotingServerInterceptorGroup);
} }
registerProcessor(); registerProcessor();
...@@ -350,7 +360,6 @@ public class SnodeController { ...@@ -350,7 +360,6 @@ public class SnodeController {
} }
public void start() { public void start() {
initialize();
if (snodeServer != null) { if (snodeServer != null) {
this.snodeServer.start(); this.snodeServer.start();
} }
......
...@@ -20,7 +20,9 @@ import ch.qos.logback.classic.LoggerContext; ...@@ -20,7 +20,9 @@ import ch.qos.logback.classic.LoggerContext;
import ch.qos.logback.classic.joran.JoranConfigurator; import ch.qos.logback.classic.joran.JoranConfigurator;
import ch.qos.logback.core.joran.spi.JoranException; import ch.qos.logback.core.joran.spi.JoranException;
import java.io.BufferedInputStream; import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.util.Properties; import java.util.Properties;
...@@ -32,6 +34,7 @@ import org.apache.commons.cli.PosixParser; ...@@ -32,6 +34,7 @@ import org.apache.commons.cli.PosixParser;
import org.apache.rocketmq.broker.BrokerController; import org.apache.rocketmq.broker.BrokerController;
import org.apache.rocketmq.broker.BrokerStartup; import org.apache.rocketmq.broker.BrokerStartup;
import org.apache.rocketmq.common.MixAll; import org.apache.rocketmq.common.MixAll;
import org.apache.rocketmq.common.MqttConfig;
import org.apache.rocketmq.common.SnodeConfig; import org.apache.rocketmq.common.SnodeConfig;
import org.apache.rocketmq.common.constant.LoggerName; import org.apache.rocketmq.common.constant.LoggerName;
import org.apache.rocketmq.logging.InternalLogger; import org.apache.rocketmq.logging.InternalLogger;
...@@ -48,19 +51,22 @@ import org.slf4j.LoggerFactory; ...@@ -48,19 +51,22 @@ import org.slf4j.LoggerFactory;
import static org.apache.rocketmq.remoting.netty.TlsSystemConfig.TLS_ENABLE; import static org.apache.rocketmq.remoting.netty.TlsSystemConfig.TLS_ENABLE;
public class SnodeStartup { public class SnodeStartup {
private static InternalLogger log; private static InternalLogger log = InternalLoggerFactory.getLogger(LoggerName.SNODE_LOGGER_NAME);
public static Properties properties = null; public static Properties properties = null;
public static CommandLine commandLine = null; public static CommandLine commandLine = null;
public static String configFile = null; public static String configFile = null;
private static final String DEFAULT_MQTT_CONFIG_FILE = "/conf/mqtt.properties";
private static String mqttConfigFileName = System.getProperty("rocketmq.mqtt.config", DEFAULT_MQTT_CONFIG_FILE);
public static void main(String[] args) throws IOException, JoranException { public static void main(String[] args) throws IOException, JoranException {
SnodeConfig snodeConfig = loadConfig(args); SnodeConfig snodeConfig = loadConfig(args);
MqttConfig mqttConfig = loadMqttConfig(snodeConfig);
if (snodeConfig.isEmbeddedModeEnable()) { if (snodeConfig.isEmbeddedModeEnable()) {
BrokerController brokerController = BrokerStartup.createBrokerController(args); BrokerController brokerController = BrokerStartup.createBrokerController(args);
BrokerStartup.start(brokerController); BrokerStartup.start(brokerController);
snodeConfig.setSnodeName(brokerController.getBrokerConfig().getBrokerName()); snodeConfig.setSnodeName(brokerController.getBrokerConfig().getBrokerName());
} }
SnodeController snodeController = createSnodeController(snodeConfig); SnodeController snodeController = createSnodeController(snodeConfig, mqttConfig);
startup(snodeController); startup(snodeController);
} }
...@@ -94,7 +100,6 @@ public class SnodeStartup { ...@@ -94,7 +100,6 @@ public class SnodeStartup {
SnodeConfig snodeConfig = new SnodeConfig(); SnodeConfig snodeConfig = new SnodeConfig();
final ServerConfig nettyServerConfig = new ServerConfig(); final ServerConfig nettyServerConfig = new ServerConfig();
final ClientConfig nettyClientConfig = new ClientConfig(); final ClientConfig nettyClientConfig = new ClientConfig();
nettyServerConfig.setListenPort(snodeConfig.getListenPort()); nettyServerConfig.setListenPort(snodeConfig.getListenPort());
nettyClientConfig.setUseTLS(Boolean.parseBoolean(System.getProperty(TLS_ENABLE, nettyClientConfig.setUseTLS(Boolean.parseBoolean(System.getProperty(TLS_ENABLE,
String.valueOf(TlsSystemConfig.tlsMode == TlsMode.ENFORCING)))); String.valueOf(TlsSystemConfig.tlsMode == TlsMode.ENFORCING))));
...@@ -142,12 +147,25 @@ public class SnodeStartup { ...@@ -142,12 +147,25 @@ public class SnodeStartup {
return snodeConfig; return snodeConfig;
} }
public static SnodeController createSnodeController(SnodeConfig snodeConfig) throws JoranException { public static MqttConfig loadMqttConfig(SnodeConfig snodeConfig) throws IOException {
MqttConfig mqttConfig = new MqttConfig();
final ServerConfig mqttServerConfig = new ServerConfig();
final ClientConfig mqttClientConfig = new ClientConfig();
mqttServerConfig.setListenPort(mqttConfig.getListenPort());
String file = snodeConfig.getRocketmqHome() + File.separator + mqttConfigFileName;
loadMqttProperties(file, mqttServerConfig, mqttClientConfig);
mqttConfig.setMqttServerConfig(mqttServerConfig);
mqttConfig.setMqttClientConfig(mqttClientConfig);
MixAll.printObjectProperties(log, mqttConfig);
MixAll.printObjectProperties(log, mqttConfig.getMqttServerConfig());
MixAll.printObjectProperties(log, mqttConfig.getMqttClientConfig());
return mqttConfig;
}
public static SnodeController createSnodeController(SnodeConfig snodeConfig, MqttConfig mqttConfig) throws JoranException {
final SnodeController snodeController = new SnodeController( final SnodeController snodeController = new SnodeController(snodeConfig, mqttConfig);
snodeConfig.getNettyServerConfig(),
snodeConfig.getNettyClientConfig(),
snodeConfig);
boolean initResult = snodeController.initialize(); boolean initResult = snodeController.initialize();
if (!initResult) { if (!initResult) {
...@@ -199,5 +217,21 @@ public class SnodeStartup { ...@@ -199,5 +217,21 @@ public class SnodeStartup {
return options; return options;
} }
private static void loadMqttProperties(String file, ServerConfig mqttServerConfig,
ClientConfig mqttClientConfig) throws IOException {
InputStream in;
try {
in = new BufferedInputStream(new FileInputStream(file));
Properties properties = new Properties();
properties.load(in);
MixAll.properties2Object(properties, mqttServerConfig);
MixAll.properties2Object(properties, mqttClientConfig);
in.close();
} catch (FileNotFoundException e) {
log.info("The mqtt config file is not found. filePath={}", file);
}
}
} }
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
package org.apache.rocketmq.snode.processor; package org.apache.rocketmq.snode.processor;
import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled;
import io.netty.handler.codec.mqtt.MqttConnectMessage; import io.netty.handler.codec.mqtt.MqttConnectMessage;
import io.netty.handler.codec.mqtt.MqttConnectPayload; import io.netty.handler.codec.mqtt.MqttConnectPayload;
import io.netty.handler.codec.mqtt.MqttConnectVariableHeader; import io.netty.handler.codec.mqtt.MqttConnectVariableHeader;
...@@ -41,6 +41,7 @@ import org.apache.rocketmq.remoting.RequestProcessor; ...@@ -41,6 +41,7 @@ import org.apache.rocketmq.remoting.RequestProcessor;
import org.apache.rocketmq.remoting.exception.RemotingCommandException; import org.apache.rocketmq.remoting.exception.RemotingCommandException;
import org.apache.rocketmq.remoting.protocol.RemotingCommand; import org.apache.rocketmq.remoting.protocol.RemotingCommand;
import org.apache.rocketmq.remoting.transport.mqtt.MqttHeader; import org.apache.rocketmq.remoting.transport.mqtt.MqttHeader;
import org.apache.rocketmq.remoting.util.MqttEncodeDecodeUtil;
import org.apache.rocketmq.snode.SnodeController; import org.apache.rocketmq.snode.SnodeController;
import org.apache.rocketmq.snode.processor.mqtthandler.MessageHandler; import org.apache.rocketmq.snode.processor.mqtthandler.MessageHandler;
import org.apache.rocketmq.snode.processor.mqtthandler.MqttConnectMessageHandler; import org.apache.rocketmq.snode.processor.mqtthandler.MqttConnectMessageHandler;
...@@ -98,16 +99,18 @@ public class DefaultMqttMessageProcessor implements RequestProcessor { ...@@ -98,16 +99,18 @@ public class DefaultMqttMessageProcessor implements RequestProcessor {
mqttHeader.isHasPassword(), mqttHeader.isWillRetain(), mqttHeader.isHasPassword(), mqttHeader.isWillRetain(),
mqttHeader.getWillQos(), mqttHeader.isWillFlag(), mqttHeader.getWillQos(), mqttHeader.isWillFlag(),
mqttHeader.isCleanSession(), mqttHeader.getKeepAliveTimeSeconds()); mqttHeader.isCleanSession(), mqttHeader.getKeepAliveTimeSeconds());
MqttConnectPayload mqttConnectPayload = (MqttConnectPayload) message.getPayload(); // MqttConnectPayload mqttConnectPayload = (MqttConnectPayload) message.getPayload();
MqttConnectPayload mqttConnectPayload = (MqttConnectPayload) MqttEncodeDecodeUtil.decode(message.getBody(), MqttConnectPayload.class);
mqttMessage = new MqttConnectMessage(fixedHeader, mqttConnectVariableHeader, mqttConnectPayload); mqttMessage = new MqttConnectMessage(fixedHeader, mqttConnectVariableHeader, mqttConnectPayload);
break; break;
case PUBLISH: case PUBLISH:
MqttPublishVariableHeader mqttPublishVariableHeader = new MqttPublishVariableHeader(mqttHeader.getTopicName(), mqttHeader.getPacketId()); MqttPublishVariableHeader mqttPublishVariableHeader = new MqttPublishVariableHeader(mqttHeader.getTopicName(), mqttHeader.getPacketId());
mqttMessage = new MqttPublishMessage(fixedHeader, mqttPublishVariableHeader, (ByteBuf) message.getPayload()); mqttMessage = new MqttPublishMessage(fixedHeader, mqttPublishVariableHeader, Unpooled.copiedBuffer(message.getBody()));
break; break;
case SUBSCRIBE: case SUBSCRIBE:
MqttMessageIdVariableHeader mqttMessageIdVariableHeader = MqttMessageIdVariableHeader.from(mqttHeader.getMessageId()); MqttMessageIdVariableHeader mqttMessageIdVariableHeader = MqttMessageIdVariableHeader.from(mqttHeader.getMessageId());
mqttMessage = new MqttSubscribeMessage(fixedHeader, mqttMessageIdVariableHeader, (MqttSubscribePayload) message.getPayload()); MqttSubscribePayload mqttSubscribePayload = (MqttSubscribePayload) MqttEncodeDecodeUtil.decode(message.getBody(), MqttSubscribePayload.class);
mqttMessage = new MqttSubscribeMessage(fixedHeader, mqttMessageIdVariableHeader, mqttSubscribePayload);
break; break;
case UNSUBSCRIBE: case UNSUBSCRIBE:
case PINGREQ: case PINGREQ:
......
...@@ -38,6 +38,7 @@ import org.apache.rocketmq.logging.InternalLoggerFactory; ...@@ -38,6 +38,7 @@ import org.apache.rocketmq.logging.InternalLoggerFactory;
import org.apache.rocketmq.remoting.RemotingChannel; import org.apache.rocketmq.remoting.RemotingChannel;
import org.apache.rocketmq.remoting.protocol.RemotingCommand; import org.apache.rocketmq.remoting.protocol.RemotingCommand;
import org.apache.rocketmq.remoting.transport.mqtt.MqttHeader; import org.apache.rocketmq.remoting.transport.mqtt.MqttHeader;
import org.apache.rocketmq.remoting.util.MqttEncodeDecodeUtil;
import org.apache.rocketmq.snode.SnodeController; import org.apache.rocketmq.snode.SnodeController;
import org.apache.rocketmq.snode.client.Client; import org.apache.rocketmq.snode.client.Client;
import org.apache.rocketmq.snode.client.impl.IOTClientManagerImpl; import org.apache.rocketmq.snode.client.impl.IOTClientManagerImpl;
...@@ -104,7 +105,7 @@ public class MqttSubscribeMessageHandler implements MessageHandler { ...@@ -104,7 +105,7 @@ public class MqttSubscribeMessageHandler implements MessageHandler {
List<Integer> grantQoss = doSubscribe(client, payload.topicSubscriptions(), iotClientManager); List<Integer> grantQoss = doSubscribe(client, payload.topicSubscriptions(), iotClientManager);
//Publish retained messages to subscribers. //Publish retained messages to subscribers.
MqttSubAckPayload mqttSubAckPayload = new MqttSubAckPayload(grantQoss); MqttSubAckPayload mqttSubAckPayload = new MqttSubAckPayload(grantQoss);
command.setPayload(mqttSubAckPayload); command.setBody(MqttEncodeDecodeUtil.encode(mqttSubAckPayload));
mqttHeader.setRemainingLength(0x02 + mqttSubAckPayload.grantedQoSLevels().size()); mqttHeader.setRemainingLength(0x02 + mqttSubAckPayload.grantedQoSLevels().size());
command.setRemark(null); command.setRemark(null);
command.setCode(ResponseCode.SUCCESS); command.setCode(ResponseCode.SUCCESS);
......
...@@ -53,12 +53,12 @@ public class MqttPushServiceImpl { ...@@ -53,12 +53,12 @@ public class MqttPushServiceImpl {
public MqttPushServiceImpl(final SnodeController snodeController) { public MqttPushServiceImpl(final SnodeController snodeController) {
this.snodeController = snodeController; this.snodeController = snodeController;
pushMqttMessageExecutorService = ThreadUtils.newThreadPoolExecutor( pushMqttMessageExecutorService = ThreadUtils.newThreadPoolExecutor(
this.snodeController.getSnodeConfig().getSnodePushMqttMessageMinPoolSize(), this.snodeController.getMqttConfig().getPushMqttMessageMinPoolSize(),
this.snodeController.getSnodeConfig().getSnodePushMqttMessageMaxPoolSize(), this.snodeController.getMqttConfig().getPushMqttMessageMaxPoolSize(),
3000, 3000,
TimeUnit.MILLISECONDS, TimeUnit.MILLISECONDS,
new ArrayBlockingQueue<>(this.snodeController.getSnodeConfig().getSnodePushMqttMessageThreadPoolQueueCapacity()), new ArrayBlockingQueue<>(this.snodeController.getMqttConfig().getPushMqttMessageThreadPoolQueueCapacity()),
"SnodePushMqttMessageThread", "pushMqttMessageThread",
false); false);
} }
...@@ -106,12 +106,14 @@ public class MqttPushServiceImpl { ...@@ -106,12 +106,14 @@ public class MqttPushServiceImpl {
if (client.getRemotingChannel() instanceof NettyChannelHandlerContextImpl) { if (client.getRemotingChannel() instanceof NettyChannelHandlerContextImpl) {
remotingChannel = new NettyChannelImpl(((NettyChannelHandlerContextImpl) client.getRemotingChannel()).getChannelHandlerContext().channel()); remotingChannel = new NettyChannelImpl(((NettyChannelHandlerContextImpl) client.getRemotingChannel()).getChannelHandlerContext().channel());
} }
requestCommand.setPayload(message.copy()); byte[] body = new byte[message.readableBytes()];
message.readBytes(body);
requestCommand.setBody(body);
snodeController.getMqttRemotingServer().push(remotingChannel, requestCommand, SnodeConstant.DEFAULT_TIMEOUT_MILLS); snodeController.getMqttRemotingServer().push(remotingChannel, requestCommand, SnodeConstant.DEFAULT_TIMEOUT_MILLS);
} }
} catch (Exception ex) { } catch (Exception ex) {
log.warn("Exception was thrown when pushing MQTT message to topic: {}, exception={}", topic, ex.getMessage()); log.warn("Exception was thrown when pushing MQTT message to topic: {}, exception={}", topic, ex.getMessage());
}finally { } finally {
System.out.println("Release Bytebuf"); System.out.println("Release Bytebuf");
ReferenceCountUtil.release(message); ReferenceCountUtil.release(message);
} }
...@@ -136,7 +138,6 @@ public class MqttPushServiceImpl { ...@@ -136,7 +138,6 @@ public class MqttPushServiceImpl {
mqttHeader.setRemainingLength(4 + topic.getBytes().length + message.readableBytes()); mqttHeader.setRemainingLength(4 + topic.getBytes().length + message.readableBytes());
RemotingCommand pushMessage = RemotingCommand.createRequestCommand(RequestCode.MQTT_MESSAGE, mqttHeader); RemotingCommand pushMessage = RemotingCommand.createRequestCommand(RequestCode.MQTT_MESSAGE, mqttHeader);
// pushMessage.setPayload(message);
return pushMessage; return pushMessage;
} }
......
...@@ -16,8 +16,8 @@ ...@@ -16,8 +16,8 @@
*/ */
package org.apache.rocketmq.snode; package org.apache.rocketmq.snode;
import org.apache.rocketmq.common.MqttConfig;
import org.apache.rocketmq.common.SnodeConfig; import org.apache.rocketmq.common.SnodeConfig;
import org.apache.rocketmq.remoting.ClientConfig;
import org.apache.rocketmq.remoting.ServerConfig; import org.apache.rocketmq.remoting.ServerConfig;
import org.junit.Test; import org.junit.Test;
...@@ -29,10 +29,7 @@ public class SnodeControllerTest { ...@@ -29,10 +29,7 @@ public class SnodeControllerTest {
public void testSnodeRestart() { public void testSnodeRestart() {
ServerConfig serverConfig = new ServerConfig(); ServerConfig serverConfig = new ServerConfig();
serverConfig.setListenPort(10912); serverConfig.setListenPort(10912);
SnodeController snodeController = new SnodeController( SnodeController snodeController = new SnodeController(new SnodeConfig(), new MqttConfig());
serverConfig,
new ClientConfig(),
new SnodeConfig());
assertThat(snodeController.initialize()); assertThat(snodeController.initialize());
snodeController.start(); snodeController.start();
snodeController.shutdown(); snodeController.shutdown();
...@@ -44,10 +41,7 @@ public class SnodeControllerTest { ...@@ -44,10 +41,7 @@ public class SnodeControllerTest {
System.setProperty("rocketmq.acl.plain.file", "/conf/plain_acl.yml"); System.setProperty("rocketmq.acl.plain.file", "/conf/plain_acl.yml");
SnodeConfig snodeConfig = new SnodeConfig(); SnodeConfig snodeConfig = new SnodeConfig();
snodeConfig.setAclEnable(true); snodeConfig.setAclEnable(true);
SnodeController snodeController = new SnodeController( SnodeController snodeController = new SnodeController(new SnodeConfig(), new MqttConfig());
new ServerConfig(),
new ClientConfig(),
snodeConfig);
assertThat(snodeController.initialize()); assertThat(snodeController.initialize());
snodeController.start(); snodeController.start();
snodeController.shutdown(); snodeController.shutdown();
......
...@@ -20,14 +20,14 @@ import io.netty.handler.codec.mqtt.MqttConnectPayload; ...@@ -20,14 +20,14 @@ import io.netty.handler.codec.mqtt.MqttConnectPayload;
import io.netty.handler.codec.mqtt.MqttMessageType; import io.netty.handler.codec.mqtt.MqttMessageType;
import io.netty.handler.codec.mqtt.MqttQoS; import io.netty.handler.codec.mqtt.MqttQoS;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import org.apache.rocketmq.common.MqttConfig;
import org.apache.rocketmq.common.SnodeConfig; import org.apache.rocketmq.common.SnodeConfig;
import org.apache.rocketmq.common.protocol.RequestCode; import org.apache.rocketmq.common.protocol.RequestCode;
import org.apache.rocketmq.remoting.ClientConfig;
import org.apache.rocketmq.remoting.RemotingChannel; import org.apache.rocketmq.remoting.RemotingChannel;
import org.apache.rocketmq.remoting.ServerConfig;
import org.apache.rocketmq.remoting.exception.RemotingCommandException; import org.apache.rocketmq.remoting.exception.RemotingCommandException;
import org.apache.rocketmq.remoting.protocol.RemotingCommand; import org.apache.rocketmq.remoting.protocol.RemotingCommand;
import org.apache.rocketmq.remoting.transport.mqtt.MqttHeader; import org.apache.rocketmq.remoting.transport.mqtt.MqttHeader;
import org.apache.rocketmq.remoting.util.MqttEncodeDecodeUtil;
import org.apache.rocketmq.snode.SnodeController; import org.apache.rocketmq.snode.SnodeController;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
...@@ -41,7 +41,7 @@ public class DefaultMqttMessageProcessorTest { ...@@ -41,7 +41,7 @@ public class DefaultMqttMessageProcessorTest {
private DefaultMqttMessageProcessor defaultMqttMessageProcessor; private DefaultMqttMessageProcessor defaultMqttMessageProcessor;
@Spy @Spy
private SnodeController snodeController = new SnodeController(new ServerConfig(), new ClientConfig(), new SnodeConfig()); private SnodeController snodeController = new SnodeController(new SnodeConfig(), new MqttConfig());
@Mock @Mock
private RemotingChannel remotingChannel; private RemotingChannel remotingChannel;
...@@ -88,7 +88,7 @@ public class DefaultMqttMessageProcessorTest { ...@@ -88,7 +88,7 @@ public class DefaultMqttMessageProcessorTest {
MqttHeader mqttHeader = createMqttConnectMesssageHeader(); MqttHeader mqttHeader = createMqttConnectMesssageHeader();
RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.MQTT_MESSAGE, mqttHeader); RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.MQTT_MESSAGE, mqttHeader);
MqttConnectPayload payload = new MqttConnectPayload("1234567", "testTopic", "willMessage".getBytes(), null, "1234567".getBytes()); MqttConnectPayload payload = new MqttConnectPayload("1234567", "testTopic", "willMessage".getBytes(), null, "1234567".getBytes());
request.setPayload(payload); request.setBody(MqttEncodeDecodeUtil.encode(payload));
return request; return request;
} }
} }
...@@ -22,10 +22,9 @@ import io.netty.handler.codec.mqtt.MqttConnectVariableHeader; ...@@ -22,10 +22,9 @@ import io.netty.handler.codec.mqtt.MqttConnectVariableHeader;
import io.netty.handler.codec.mqtt.MqttFixedHeader; import io.netty.handler.codec.mqtt.MqttFixedHeader;
import io.netty.handler.codec.mqtt.MqttMessageType; import io.netty.handler.codec.mqtt.MqttMessageType;
import io.netty.handler.codec.mqtt.MqttQoS; import io.netty.handler.codec.mqtt.MqttQoS;
import org.apache.rocketmq.common.MqttConfig;
import org.apache.rocketmq.common.SnodeConfig; import org.apache.rocketmq.common.SnodeConfig;
import org.apache.rocketmq.remoting.ClientConfig;
import org.apache.rocketmq.remoting.RemotingChannel; import org.apache.rocketmq.remoting.RemotingChannel;
import org.apache.rocketmq.remoting.ServerConfig;
import org.apache.rocketmq.snode.SnodeController; import org.apache.rocketmq.snode.SnodeController;
import org.apache.rocketmq.snode.processor.mqtthandler.MqttConnectMessageHandler; import org.apache.rocketmq.snode.processor.mqtthandler.MqttConnectMessageHandler;
import org.junit.Test; import org.junit.Test;
...@@ -42,12 +41,10 @@ public class MqttConnectMessageHandlerTest { ...@@ -42,12 +41,10 @@ public class MqttConnectMessageHandlerTest {
@Test @Test
public void testHandlerMessage() throws Exception { public void testHandlerMessage() throws Exception {
MqttConnectMessageHandler mqttConnectMessageHandler = new MqttConnectMessageHandler( MqttConnectMessageHandler mqttConnectMessageHandler = new MqttConnectMessageHandler(new SnodeController(new SnodeConfig(), new MqttConfig()));
new SnodeController(new ServerConfig(), new ClientConfig(), new SnodeConfig()));
MqttConnectPayload payload = new MqttConnectPayload("1234567", "testTopic", "willMessage".getBytes(), null, "1234567".getBytes()); MqttConnectPayload payload = new MqttConnectPayload("1234567", "testTopic", "willMessage".getBytes(), null, "1234567".getBytes());
MqttConnectMessage mqttConnectMessage = new MqttConnectMessage(new MqttFixedHeader( MqttConnectMessage mqttConnectMessage = new MqttConnectMessage(new MqttFixedHeader(
MqttMessageType.CONNECT, false, MqttQoS.AT_MOST_ONCE, false, 200),new MqttConnectVariableHeader(null,4,false,false,false,0,false,false,50),new MqttConnectPayload("abcd", "ttest", "message".getBytes(),"user","password".getBytes())); MqttMessageType.CONNECT, false, MqttQoS.AT_MOST_ONCE, false, 200), new MqttConnectVariableHeader(null, 4, false, false, false, 0, false, false, 50), new MqttConnectPayload("abcd", "ttest", "message".getBytes(), "user", "password".getBytes()));
mqttConnectMessageHandler.handleMessage(mqttConnectMessage, remotingChannel); mqttConnectMessageHandler.handleMessage(mqttConnectMessage, remotingChannel);
} }
......
...@@ -20,11 +20,10 @@ import io.netty.handler.codec.mqtt.MqttFixedHeader; ...@@ -20,11 +20,10 @@ import io.netty.handler.codec.mqtt.MqttFixedHeader;
import io.netty.handler.codec.mqtt.MqttMessage; import io.netty.handler.codec.mqtt.MqttMessage;
import io.netty.handler.codec.mqtt.MqttMessageType; import io.netty.handler.codec.mqtt.MqttMessageType;
import io.netty.handler.codec.mqtt.MqttQoS; import io.netty.handler.codec.mqtt.MqttQoS;
import org.apache.rocketmq.common.MqttConfig;
import org.apache.rocketmq.common.SnodeConfig; import org.apache.rocketmq.common.SnodeConfig;
import org.apache.rocketmq.common.message.mqtt.WillMessage; import org.apache.rocketmq.common.message.mqtt.WillMessage;
import org.apache.rocketmq.remoting.ClientConfig;
import org.apache.rocketmq.remoting.RemotingChannel; import org.apache.rocketmq.remoting.RemotingChannel;
import org.apache.rocketmq.remoting.ServerConfig;
import org.apache.rocketmq.snode.SnodeController; import org.apache.rocketmq.snode.SnodeController;
import org.apache.rocketmq.snode.client.Client; import org.apache.rocketmq.snode.client.Client;
import org.apache.rocketmq.snode.client.impl.IOTClientManagerImpl; import org.apache.rocketmq.snode.client.impl.IOTClientManagerImpl;
...@@ -43,8 +42,7 @@ public class MqttDisconnectMessageHandlerTest { ...@@ -43,8 +42,7 @@ public class MqttDisconnectMessageHandlerTest {
@Test @Test
public void testHandlerMessage() throws Exception { public void testHandlerMessage() throws Exception {
SnodeController snodeController = new SnodeController(new ServerConfig(), SnodeController snodeController = new SnodeController(new SnodeConfig(), new MqttConfig());
new ClientConfig(), new SnodeConfig());
MqttDisconnectMessageHandler mqttDisconnectMessageHandler = new MqttDisconnectMessageHandler( MqttDisconnectMessageHandler mqttDisconnectMessageHandler = new MqttDisconnectMessageHandler(
snodeController); snodeController);
Client client = new Client(); Client client = new Client();
......
...@@ -18,13 +18,12 @@ package org.apache.rocketmq.snode.processor; ...@@ -18,13 +18,12 @@ package org.apache.rocketmq.snode.processor;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
import org.apache.rocketmq.common.MixAll; import org.apache.rocketmq.common.MixAll;
import org.apache.rocketmq.common.MqttConfig;
import org.apache.rocketmq.common.SnodeConfig; import org.apache.rocketmq.common.SnodeConfig;
import org.apache.rocketmq.common.protocol.RequestCode; import org.apache.rocketmq.common.protocol.RequestCode;
import org.apache.rocketmq.common.protocol.ResponseCode; import org.apache.rocketmq.common.protocol.ResponseCode;
import org.apache.rocketmq.common.protocol.header.SendMessageRequestHeaderV2; import org.apache.rocketmq.common.protocol.header.SendMessageRequestHeaderV2;
import org.apache.rocketmq.remoting.ClientConfig;
import org.apache.rocketmq.remoting.RemotingChannel; import org.apache.rocketmq.remoting.RemotingChannel;
import org.apache.rocketmq.remoting.ServerConfig;
import org.apache.rocketmq.remoting.exception.RemotingCommandException; import org.apache.rocketmq.remoting.exception.RemotingCommandException;
import org.apache.rocketmq.remoting.netty.CodecHelper; import org.apache.rocketmq.remoting.netty.CodecHelper;
import org.apache.rocketmq.remoting.protocol.RemotingCommand; import org.apache.rocketmq.remoting.protocol.RemotingCommand;
...@@ -48,7 +47,7 @@ public class SendMessageProcessorTest { ...@@ -48,7 +47,7 @@ public class SendMessageProcessorTest {
private SendMessageProcessor sendMessageProcessor; private SendMessageProcessor sendMessageProcessor;
@Spy @Spy
private SnodeController snodeController = new SnodeController(new ServerConfig(), new ClientConfig(), new SnodeConfig()); private SnodeController snodeController = new SnodeController(new SnodeConfig(), new MqttConfig());
@Mock @Mock
private RemotingChannel remotingChannel; private RemotingChannel remotingChannel;
...@@ -56,7 +55,7 @@ public class SendMessageProcessorTest { ...@@ -56,7 +55,7 @@ public class SendMessageProcessorTest {
private String topic = "snodeTopic"; private String topic = "snodeTopic";
private String group = "snodeGroup"; private String group = "snodeGroup";
@Mock @Mock
private EnodeService enodeService; private EnodeService enodeService;
......
...@@ -18,9 +18,8 @@ package org.apache.rocketmq.snode.service; ...@@ -18,9 +18,8 @@ package org.apache.rocketmq.snode.service;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.apache.rocketmq.common.MqttConfig;
import org.apache.rocketmq.common.SnodeConfig; import org.apache.rocketmq.common.SnodeConfig;
import org.apache.rocketmq.remoting.ClientConfig;
import org.apache.rocketmq.remoting.ServerConfig;
import org.apache.rocketmq.remoting.exception.RemotingConnectException; import org.apache.rocketmq.remoting.exception.RemotingConnectException;
import org.apache.rocketmq.remoting.exception.RemotingSendRequestException; import org.apache.rocketmq.remoting.exception.RemotingSendRequestException;
import org.apache.rocketmq.remoting.exception.RemotingTimeoutException; import org.apache.rocketmq.remoting.exception.RemotingTimeoutException;
...@@ -46,7 +45,7 @@ import static org.mockito.Mockito.when; ...@@ -46,7 +45,7 @@ import static org.mockito.Mockito.when;
public class NnodeServiceImplTest extends SnodeTestBase { public class NnodeServiceImplTest extends SnodeTestBase {
@Spy @Spy
private SnodeController snodeController = new SnodeController(new ServerConfig(), new ClientConfig(), new SnodeConfig()); private SnodeController snodeController = new SnodeController(new SnodeConfig(), new MqttConfig());
@Mock @Mock
private NettyRemotingClient remotingClient; private NettyRemotingClient remotingClient;
......
...@@ -18,13 +18,12 @@ package org.apache.rocketmq.snode.service; ...@@ -18,13 +18,12 @@ package org.apache.rocketmq.snode.service;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import org.apache.rocketmq.common.MqttConfig;
import org.apache.rocketmq.common.SnodeConfig; import org.apache.rocketmq.common.SnodeConfig;
import org.apache.rocketmq.common.protocol.RequestCode; import org.apache.rocketmq.common.protocol.RequestCode;
import org.apache.rocketmq.common.protocol.ResponseCode; import org.apache.rocketmq.common.protocol.ResponseCode;
import org.apache.rocketmq.common.protocol.header.PullMessageRequestHeader; import org.apache.rocketmq.common.protocol.header.PullMessageRequestHeader;
import org.apache.rocketmq.remoting.ClientConfig;
import org.apache.rocketmq.remoting.InvokeCallback; import org.apache.rocketmq.remoting.InvokeCallback;
import org.apache.rocketmq.remoting.ServerConfig;
import org.apache.rocketmq.remoting.netty.ResponseFuture; import org.apache.rocketmq.remoting.netty.ResponseFuture;
import org.apache.rocketmq.remoting.protocol.RemotingCommand; import org.apache.rocketmq.remoting.protocol.RemotingCommand;
import org.apache.rocketmq.remoting.transport.rocketmq.NettyRemotingClient; import org.apache.rocketmq.remoting.transport.rocketmq.NettyRemotingClient;
...@@ -56,7 +55,7 @@ public class RemoteEnodeServiceImplTest extends SnodeTestBase { ...@@ -56,7 +55,7 @@ public class RemoteEnodeServiceImplTest extends SnodeTestBase {
private EnodeService enodeService; private EnodeService enodeService;
@Spy @Spy
private SnodeController snodeController = new SnodeController(new ServerConfig(), new ClientConfig(), new SnodeConfig()); private SnodeController snodeController = new SnodeController(new SnodeConfig(), new MqttConfig());
@Mock @Mock
private NnodeService nnodeService; private NnodeService nnodeService;
......
...@@ -16,9 +16,8 @@ ...@@ -16,9 +16,8 @@
*/ */
package org.apache.rocketmq.snode.service; package org.apache.rocketmq.snode.service;
import org.apache.rocketmq.common.MqttConfig;
import org.apache.rocketmq.common.SnodeConfig; import org.apache.rocketmq.common.SnodeConfig;
import org.apache.rocketmq.remoting.ClientConfig;
import org.apache.rocketmq.remoting.ServerConfig;
import org.apache.rocketmq.snode.SnodeController; import org.apache.rocketmq.snode.SnodeController;
import org.apache.rocketmq.snode.client.SlowConsumerService; import org.apache.rocketmq.snode.client.SlowConsumerService;
import org.apache.rocketmq.snode.client.impl.SlowConsumerServiceImpl; import org.apache.rocketmq.snode.client.impl.SlowConsumerServiceImpl;
...@@ -38,7 +37,7 @@ import static org.mockito.Mockito.when; ...@@ -38,7 +37,7 @@ import static org.mockito.Mockito.when;
@RunWith(MockitoJUnitRunner.class) @RunWith(MockitoJUnitRunner.class)
public class SlowConsumerServiceImplTest { public class SlowConsumerServiceImplTest {
@Spy @Spy
private SnodeController snodeController = new SnodeController(new ServerConfig(), new ClientConfig(), new SnodeConfig()); private SnodeController snodeController = new SnodeController(new SnodeConfig(), new MqttConfig());
private final String enodeName = "testEndoe"; private final String enodeName = "testEndoe";
......
...@@ -16,10 +16,9 @@ ...@@ -16,10 +16,9 @@
*/ */
package org.apache.rocketmq.snode.service; package org.apache.rocketmq.snode.service;
import org.apache.rocketmq.common.MqttConfig;
import org.apache.rocketmq.common.SnodeConfig; import org.apache.rocketmq.common.SnodeConfig;
import org.apache.rocketmq.common.message.mqtt.WillMessage; import org.apache.rocketmq.common.message.mqtt.WillMessage;
import org.apache.rocketmq.remoting.ClientConfig;
import org.apache.rocketmq.remoting.ServerConfig;
import org.apache.rocketmq.snode.SnodeController; import org.apache.rocketmq.snode.SnodeController;
import org.apache.rocketmq.snode.SnodeTestBase; import org.apache.rocketmq.snode.SnodeTestBase;
import org.apache.rocketmq.snode.service.impl.WillMessageServiceImpl; import org.apache.rocketmq.snode.service.impl.WillMessageServiceImpl;
...@@ -33,8 +32,7 @@ import org.mockito.junit.MockitoJUnitRunner; ...@@ -33,8 +32,7 @@ import org.mockito.junit.MockitoJUnitRunner;
public class WillMessageServiceImplTest extends SnodeTestBase { public class WillMessageServiceImplTest extends SnodeTestBase {
@Spy @Spy
private SnodeController snodeController = new SnodeController(new ServerConfig(), private SnodeController snodeController = new SnodeController(new SnodeConfig(), new MqttConfig());
new ClientConfig(), new SnodeConfig());
private WillMessageService willMessageService; private WillMessageService willMessageService;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册