From 5ed5374bb992d9179ce2466c9bd6ea46a6301685 Mon Sep 17 00:00:00 2001 From: liuhy Date: Mon, 3 Aug 2026 06:37:29 -0700 Subject: [PATCH 1/2] [ISSUE #10793] Handle offline consumer list queries --- .../activity/ConsumerManagerActivity.java | 5 ++ .../activity/ConsumerManagerActivityTest.java | 67 +++++++++++++++++++ 2 files changed, 72 insertions(+) create mode 100644 proxy/src/test/java/org/apache/rocketmq/proxy/remoting/activity/ConsumerManagerActivityTest.java diff --git a/proxy/src/main/java/org/apache/rocketmq/proxy/remoting/activity/ConsumerManagerActivity.java b/proxy/src/main/java/org/apache/rocketmq/proxy/remoting/activity/ConsumerManagerActivity.java index ce1f1b4a514..b88be4a32bb 100644 --- a/proxy/src/main/java/org/apache/rocketmq/proxy/remoting/activity/ConsumerManagerActivity.java +++ b/proxy/src/main/java/org/apache/rocketmq/proxy/remoting/activity/ConsumerManagerActivity.java @@ -84,6 +84,11 @@ protected RemotingCommand getConsumerListByGroup(ChannelHandlerContext ctx, Remo RemotingCommand response = RemotingCommand.createResponseCommand(GetConsumerListByGroupResponseHeader.class); GetConsumerListByGroupRequestHeader header = (GetConsumerListByGroupRequestHeader) request.decodeCommandCustomHeader(GetConsumerListByGroupRequestHeader.class); ConsumerGroupInfo consumerGroupInfo = messagingProcessor.getConsumerGroupInfo(context, header.getConsumerGroup()); + if (consumerGroupInfo == null) { + response.setCode(ResponseCode.CONSUMER_NOT_ONLINE); + response.setRemark("the consumer group[" + header.getConsumerGroup() + "] not online"); + return response; + } List clientIds = consumerGroupInfo.getAllClientId(); GetConsumerListByGroupResponseBody body = new GetConsumerListByGroupResponseBody(); body.setConsumerIdList(clientIds); diff --git a/proxy/src/test/java/org/apache/rocketmq/proxy/remoting/activity/ConsumerManagerActivityTest.java b/proxy/src/test/java/org/apache/rocketmq/proxy/remoting/activity/ConsumerManagerActivityTest.java new file mode 100644 index 00000000000..4ee5b8e5c6d --- /dev/null +++ b/proxy/src/test/java/org/apache/rocketmq/proxy/remoting/activity/ConsumerManagerActivityTest.java @@ -0,0 +1,67 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.rocketmq.proxy.remoting.activity; + +import org.apache.rocketmq.proxy.common.ProxyContext; +import org.apache.rocketmq.proxy.config.InitConfigTest; +import org.apache.rocketmq.proxy.processor.MessagingProcessor; +import org.apache.rocketmq.remoting.protocol.RemotingCommand; +import org.apache.rocketmq.remoting.protocol.RequestCode; +import org.apache.rocketmq.remoting.protocol.ResponseCode; +import org.apache.rocketmq.remoting.protocol.header.GetConsumerListByGroupRequestHeader; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.junit.MockitoJUnitRunner; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.when; + +@RunWith(MockitoJUnitRunner.class) +public class ConsumerManagerActivityTest extends InitConfigTest { + private static final String CONSUMER_GROUP = "offline-group"; + + private ConsumerManagerActivity consumerManagerActivity; + + @Mock + private MessagingProcessor messagingProcessor; + + @Before + public void setup() { + this.consumerManagerActivity = new ConsumerManagerActivity(null, messagingProcessor); + } + + @Test + public void testGetConsumerListByGroupShouldReturnNotOnlineWhenGroupMissing() throws Exception { + GetConsumerListByGroupRequestHeader header = new GetConsumerListByGroupRequestHeader(); + header.setConsumerGroup(CONSUMER_GROUP); + RemotingCommand request = RemotingCommand.createRequestCommand( + RequestCode.GET_CONSUMER_LIST_BY_GROUP, header); + request.makeCustomHeaderToNet(); + when(messagingProcessor.getConsumerGroupInfo(any(), eq(CONSUMER_GROUP))).thenReturn(null); + + RemotingCommand response = consumerManagerActivity.getConsumerListByGroup( + null, request, ProxyContext.create()); + + assertThat(response.getCode()).isEqualTo(ResponseCode.CONSUMER_NOT_ONLINE); + assertThat(response.getRemark()).isEqualTo("the consumer group[offline-group] not online"); + } +} From 3485187e439525b3630fca3fd4fae0d4a7930555 Mon Sep 17 00:00:00 2001 From: liuhy Date: Tue, 4 Aug 2026 03:59:28 -0700 Subject: [PATCH 2/2] refactor(proxy): share consumer offline diagnostics --- .../proxy/remoting/activity/ConsumerManagerActivity.java | 8 ++++++-- .../remoting/activity/ConsumerManagerActivityTest.java | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/proxy/src/main/java/org/apache/rocketmq/proxy/remoting/activity/ConsumerManagerActivity.java b/proxy/src/main/java/org/apache/rocketmq/proxy/remoting/activity/ConsumerManagerActivity.java index b88be4a32bb..43f22748af0 100644 --- a/proxy/src/main/java/org/apache/rocketmq/proxy/remoting/activity/ConsumerManagerActivity.java +++ b/proxy/src/main/java/org/apache/rocketmq/proxy/remoting/activity/ConsumerManagerActivity.java @@ -86,7 +86,7 @@ protected RemotingCommand getConsumerListByGroup(ChannelHandlerContext ctx, Remo ConsumerGroupInfo consumerGroupInfo = messagingProcessor.getConsumerGroupInfo(context, header.getConsumerGroup()); if (consumerGroupInfo == null) { response.setCode(ResponseCode.CONSUMER_NOT_ONLINE); - response.setRemark("the consumer group[" + header.getConsumerGroup() + "] not online"); + response.setRemark(consumerNotOnlineRemark(header.getConsumerGroup())); return response; } List clientIds = consumerGroupInfo.getAllClientId(); @@ -130,10 +130,14 @@ protected RemotingCommand getConsumerConnectionList(ChannelHandlerContext ctx, R } response.setCode(ResponseCode.CONSUMER_NOT_ONLINE); - response.setRemark("the consumer group[" + header.getConsumerGroup() + "] not online"); + response.setRemark(consumerNotOnlineRemark(header.getConsumerGroup())); return response; } + static String consumerNotOnlineRemark(String consumerGroup) { + return "the consumer group[" + consumerGroup + "] not online"; + } + protected RemotingCommand lockBatchMQ(ChannelHandlerContext ctx, RemotingCommand request, ProxyContext context) throws Exception { final RemotingCommand response = RemotingCommand.createResponseCommand(null); diff --git a/proxy/src/test/java/org/apache/rocketmq/proxy/remoting/activity/ConsumerManagerActivityTest.java b/proxy/src/test/java/org/apache/rocketmq/proxy/remoting/activity/ConsumerManagerActivityTest.java index 4ee5b8e5c6d..59533b26ac0 100644 --- a/proxy/src/test/java/org/apache/rocketmq/proxy/remoting/activity/ConsumerManagerActivityTest.java +++ b/proxy/src/test/java/org/apache/rocketmq/proxy/remoting/activity/ConsumerManagerActivityTest.java @@ -62,6 +62,6 @@ public void testGetConsumerListByGroupShouldReturnNotOnlineWhenGroupMissing() th null, request, ProxyContext.create()); assertThat(response.getCode()).isEqualTo(ResponseCode.CONSUMER_NOT_ONLINE); - assertThat(response.getRemark()).isEqualTo("the consumer group[offline-group] not online"); + assertThat(response.getRemark()).isEqualTo(ConsumerManagerActivity.consumerNotOnlineRemark(CONSUMER_GROUP)); } }