关键两个类:
CommandPubSubDecoder.java
// Netty 读取到数据后,发送给 redission
protected void decodeCommand(Channel channel, ByteBuf in, QueueCommand data, int endIndex) throws Exception {
try {
while (in.writerIndex() > in.readerIndex()) {
if (data != null) {
if (((CommandData<Object, Object>) data).getPromise().isDone()) {
data = null;
}
}
decode(in, (CommandData<Object, Object>) data, null, channel, false, null, 0);
}
sendNext(channel, data);//数据读取完成后,调用 消息发送
} catch (Exception e) {
log.error("Unable to decode data. channel: {}, reply: {}", channel, LogHelper.toString(in), e);
if (data != null) {
data.tryFailure(e);
}
sendNext(channel);
throw e;
}
}
CommandDecoder .java
调用父类进行协议解析
@Override
protected final void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
QueueCommandHolder holder = getCommand(ctx);
QueueCommand data = null;
if (holder != null) {
data = holder.getCommand();
}
if (state() =
Netty协议解码与RedisPub/Sub事件处理:Java实现,

最低0.47元/天 解锁文章
5955

被折叠的 条评论
为什么被折叠?



