1.Netty提供的一些现成的工具
1.1 心跳检测
心跳检测本质上就是检查通道里是否有数据进出
1.2 Protobuf
io.netty.handler.codec.protobuf.ProtobufEncoder
io.netty.handler.codec.protobuf.ProtobufDecoder
https://gitee.com/spitman/learnnetty/blob/master/src/main/java/org/zyj/io/example/case6/ProtobufTestClient.java
https://gitee.com/spitman/learnnetty/blob/master/src/main/java/org/zyj/io/example/case6/ProtobufTestServer.java
1.2.1 支持多种不同的Protobuf格式
- 定义多种protobuf
- server
- handler
https://gitee.com/spitman/learnnetty/blob/master/src/main/java/org/zyj/io/example/case7/ProtobufMultiMsgServerHandler.java
1.3 HTTP
io.netty.handler.codec.http.HttpServerCodec
https://gitee.com/spitman/learnnetty/blob/master/src/main/java/org/zyj/io/example/case2/HttpServer.java
1.4 WebSocket
io.netty.handler.codec.http.websocketx.WebSocketServerProtocolHandler
https://gitee.com/spitman/learnnetty/blob/master/src/main/java/org/zyj/io/example/case5/WebsocketServer.java
1.5 其他协议
参见: io.netty.handler.codec
包
2. Netty官方示例
https://github.com/netty/netty/tree/4.1/example
3. 看看开源软件是怎么用Netty的
3.1 RocketMQ
https://gitee.com/apache/rocketmq/blob/develop/remoting/src/main/java/org/apache/rocketmq/remoting/netty/NettyRemotingServer.java
3.2 Cassandra
https://gitee.com/apache/Cassandra/blob/trunk/src/java/org/apache/cassandra/transport/Server.java