diff --git a/broker/src/main/java/org/apache/rocketmq/broker/processor/PopMessageProcessor.java b/broker/src/main/java/org/apache/rocketmq/broker/processor/PopMessageProcessor.java index 441f7de08a1..149a700e170 100644 --- a/broker/src/main/java/org/apache/rocketmq/broker/processor/PopMessageProcessor.java +++ b/broker/src/main/java/org/apache/rocketmq/broker/processor/PopMessageProcessor.java @@ -204,7 +204,7 @@ public RemotingCommand processRequest(final ChannelHandlerContext ctx, RemotingC RemotingCommand response = RemotingCommand.createResponseCommand(PopMessageResponseHeader.class); final PopMessageResponseHeader responseHeader = (PopMessageResponseHeader) response.readCustomHeader(); final PopMessageRequestHeader requestHeader = - (PopMessageRequestHeader) request.decodeCommandCustomHeader(PopMessageRequestHeader.class); + (PopMessageRequestHeader) request.decodeCommandCustomHeader(PopMessageRequestHeader.class, true); StringBuilder startOffsetInfo = new StringBuilder(64); StringBuilder msgOffsetInfo = new StringBuilder(64); StringBuilder orderCountInfo = null; diff --git a/remoting/src/main/java/org/apache/rocketmq/remoting/protocol/RemotingCommand.java b/remoting/src/main/java/org/apache/rocketmq/remoting/protocol/RemotingCommand.java index 011c81d1773..11e65894c5c 100644 --- a/remoting/src/main/java/org/apache/rocketmq/remoting/protocol/RemotingCommand.java +++ b/remoting/src/main/java/org/apache/rocketmq/remoting/protocol/RemotingCommand.java @@ -261,14 +261,19 @@ public void writeCustomHeader(CommandCustomHeader customHeader) { public CommandCustomHeader decodeCommandCustomHeader( Class classHeader) throws RemotingCommandException { - if (cachedHeader != null) { + return decodeCommandCustomHeader(classHeader, false); + } + + public CommandCustomHeader decodeCommandCustomHeader( + Class classHeader, boolean cacheAble) throws RemotingCommandException { + if (cacheAble && cachedHeader != null) { return cachedHeader; } - cachedHeader = decodeCommandCustomHeader(classHeader, true); + cachedHeader = decodeCommandCustomHeaderDirectly(classHeader, true); return cachedHeader; } - public CommandCustomHeader decodeCommandCustomHeader(Class classHeader, + public CommandCustomHeader decodeCommandCustomHeaderDirectly(Class classHeader, boolean useFastEncode) throws RemotingCommandException { CommandCustomHeader objectHeader; try { diff --git a/remoting/src/test/java/org/apache/rocketmq/remoting/protocol/header/FastCodesHeaderTest.java b/remoting/src/test/java/org/apache/rocketmq/remoting/protocol/header/FastCodesHeaderTest.java index 6bb100f574f..b6a0d631129 100644 --- a/remoting/src/test/java/org/apache/rocketmq/remoting/protocol/header/FastCodesHeaderTest.java +++ b/remoting/src/test/java/org/apache/rocketmq/remoting/protocol/header/FastCodesHeaderTest.java @@ -73,7 +73,7 @@ private HashMap buildExtFields(List fields) { private void check(RemotingCommand command, List fields, Class classHeader) throws Exception { - CommandCustomHeader o1 = command.decodeCommandCustomHeader(classHeader, false); + CommandCustomHeader o1 = command.decodeCommandCustomHeaderDirectly(classHeader, false); CommandCustomHeader o2 = classHeader.getDeclaredConstructor().newInstance(); ((FastCodesHeader)o2).decode(command.getExtFields()); for (Field f : fields) {