目录
连接上的 client 的 channelId 怎么存入 redis 中?
完整的讲解 netty 集群的搭建部署。从0讲解每一步,比如存入的数据是什么样的?多节点消息是怎么通信的?让没有搭建过的童鞋没有疑惑。例如:“唉,我存入redis中的实际是什么?我有没有写对?”
首先说下单机版 netty 的操作
普通的 springboot netty 项目,都是 springboot 项目启动加载完成后,启动netty 服务。代码如下
@Component
public class StartUpRunner implements ApplicationRunner {
// 启动 netty 服务的代码
@Override
public void run(ApplicationArguments args) throws Exception {
ServerBootstrap.bind(7177).sync();
}
}
// netty pipeline,配置 websocket,访问路径是 socket.io
@Override
protected void initChannel(NioSocketChannel ch) throws Exception {
ChannelPipeline pipeline = ch.pipeline();
pipeline.addLast(new HttpServerCodec())
.addLast(new ChunkedWriteHandler())
.addLast(new HttpObjectAggregator(1024 * 1024))
.addLast(new WebSocketServerProtocolHandler("/s