update mqtt 服务器

This commit is contained in:
Lemon
2023-12-21 10:37:21 +08:00
parent 5fbce62752
commit 36c2832f63
6 changed files with 43 additions and 46 deletions

View File

@@ -64,41 +64,9 @@ public class NettyServer implements CommandLineRunner {
} else {
log.error("NettyServer启动失败", future.cause());
}
//
// ServerBootstrap mqttBootstrap = new ServerBootstrap();
// mqttBootstrap.group(bossGroup, workerGroup);
// mqttBootstrap.channel(NioServerSocketChannel.class);
//
// mqttBootstrap.option(ChannelOption.SO_REUSEADDR, true)
// .option(ChannelOption.SO_BACKLOG, 1024)
// .option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT)
// .option(ChannelOption.SO_RCVBUF, 10485760);
//
// mqttBootstrap.childOption(ChannelOption.TCP_NODELAY, true)
// .childOption(ChannelOption.SO_KEEPALIVE, true)
// .childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT);
//
// mqttBootstrap.childHandler(new ChannelInitializer<SocketChannel>() {
// protected void initChannel(SocketChannel ch) {
// ChannelPipeline channelPipeline = ch.pipeline();
// // 设置读写空闲超时时间
// channelPipeline.addLast(new IdleStateHandler(600, 600, 1200));
// channelPipeline.addLast("encoder", MqttEncoder.INSTANCE);
// channelPipeline.addLast("decoder", new MqttDecoder());
// channelPipeline.addLast(new BootNettyMqttChannelInboundHandler());
// }
// });
// ChannelFuture future2 = mqttBootstrap.bind(address2.getPort()).sync();
// if(future2.isSuccess()){
// log.info("MqttServer启动成功, 开始监听端口:{}", address2.getPort());
// future2.channel().closeFuture().sync();
// } else {
// log.error("MqttServer启动失败", future2.cause());
// }
//关闭channel和块直到它被关闭
future.channel().closeFuture().sync();
// future2.channel().closeFuture().sync();
// 关闭channel和块直到它被关闭 (若取消注释,则 MQTT 服务器无法启动)
// future.channel().closeFuture().sync();
} catch (Exception e) {
log.error("NettyServer.start error", e);
bossGroup.shutdownGracefully();