mirror of
https://codeup.aliyun.com/67c68d4e484ca2f0a13ac3c1/ydc/jsowell-charger-web.git
synced 2026-04-23 12:35:07 +08:00
新增 netty整合mqtt协议,与车位相机通讯并保存通讯信息
This commit is contained in:
@@ -2,9 +2,7 @@ package com.jsowell.netty.server.yunkuaichong;
|
||||
|
||||
import com.jsowell.common.constant.Constants;
|
||||
import io.netty.bootstrap.ServerBootstrap;
|
||||
import io.netty.channel.ChannelFuture;
|
||||
import io.netty.channel.ChannelOption;
|
||||
import io.netty.channel.EventLoopGroup;
|
||||
import io.netty.channel.*;
|
||||
import io.netty.channel.nio.NioEventLoopGroup;
|
||||
import io.netty.channel.socket.nio.NioServerSocketChannel;
|
||||
import io.netty.handler.logging.LogLevel;
|
||||
@@ -19,11 +17,11 @@ import java.net.InetSocketAddress;
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
@Order(value = 1)
|
||||
public class NettyServer implements CommandLineRunner {
|
||||
@Resource
|
||||
private NettyServerChannelInitializer nettyServerChannelInitializer;
|
||||
|
||||
@Order(value = 1)
|
||||
@Override
|
||||
public void run(String... args) throws Exception {
|
||||
InetSocketAddress address = new InetSocketAddress(Constants.SOCKET_IP, Constants.SOCKET_PORT);
|
||||
@@ -66,8 +64,41 @@ 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();
|
||||
} catch (Exception e) {
|
||||
log.error("NettyServer.start error", e);
|
||||
bossGroup.shutdownGracefully();
|
||||
|
||||
Reference in New Issue
Block a user