1、调用writeAndFlush方法之后获取ChannelFuture;
2、新增消息发送ChannelFutureListener,监听消息发送结果,如果消息写入网络Socket成功,则Netty会回调ChannelFutureListener的operationComplete方法;
3、在消息发送ChannelFutureListener的operationComplete方法中进行性能统计。
示例代码如下:
ChannelFuture future=socketChannel.writeAndFlush(msg);
future.addListener(new ChannelFutureListener() {
@Override
public void operationComplete(ChannelFuture future) throws Exception {
logger.info("seqId={} sent",msg.getSeqId());
}
});
@Override
public void channelReadComplete(ChannelHandlerContext ctx) throws Exception {
ctx.fireChannelReadComplete();
}
还是public void channelRead0(ChannelHandlerContext ctx, RpcMsg msg)这个读到消息的早,测试
void channelWritabilityChanged(ChannelHandlerContext ctx) throws Exception;高低水位变化测试
默认水位值测试
标签:Netty,Exception,operationComplete,Socket,ChannelFutureListener,void,ctx,msg,发送到 From: https://blog.51cto.com/u_4176761/5973341