This is an automated email from the ASF dual-hosted git repository.

lizhimins pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/rocketmq-dashboard.git


The following commit(s) were added to refs/heads/master by this push:
     new 34a17ad0f fix(producer): scope the group selector suggestions to the 
requested topic (#5001)
34a17ad0f is described below

commit 34a17ad0f60e567c32798b8a07abf815bc44ab44
Author: 烤化の初雪 <[email protected]>
AuthorDate: Fri Nov 27 12:20:39 2026 +0800

    fix(producer): scope the group selector suggestions to the requested topic 
(#5001)
---
 .../provider/apache/RocketMQClientProvider.java    | 21 ++++++++++-
 .../apache/RocketMQClientProviderTest.java         | 44 +++++++++++++++++++++-
 2 files changed, 62 insertions(+), 3 deletions(-)

diff --git 
a/server/src/main/java/org/apache/rocketmq/studio/provider/apache/RocketMQClientProvider.java
 
b/server/src/main/java/org/apache/rocketmq/studio/provider/apache/RocketMQClientProvider.java
index 81a358da7..f20b28651 100644
--- 
a/server/src/main/java/org/apache/rocketmq/studio/provider/apache/RocketMQClientProvider.java
+++ 
b/server/src/main/java/org/apache/rocketmq/studio/provider/apache/RocketMQClientProvider.java
@@ -42,6 +42,7 @@ import 
org.apache.rocketmq.studio.common.domain.enums.Protocol;
 import org.apache.rocketmq.studio.common.util.MqResponseCodes;
 import org.apache.rocketmq.studio.common.util.SystemGroupFilter;
 import org.apache.rocketmq.tools.admin.MQAdminExt;
+import org.springframework.util.StringUtils;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.context.annotation.Primary;
@@ -126,7 +127,25 @@ public class RocketMQClientProvider implements 
ClientProvider {
     }
 
     private List<String> findProducerGroups(MQAdminExt adminExt, String topic, 
String query, int limit) {
-        return scanProducerGroups(adminExt, query, limit).groups();
+        ProducerGroupScanResult scan = scanProducerGroups(adminExt, query, 
limit);
+        if (!StringUtils.hasText(topic)) {
+            return scan.groups();
+        }
+        // The whole-broker producer table is keyed by group only, so a 
topic-scoped selector has to
+        // verify each candidate against the topic the way the follow-up 
connection query will;
+        // otherwise picking a suggestion yields an empty "no connection" list.
+        List<String> scopedGroups = new ArrayList<>();
+        for (String group : scan.groups()) {
+            try {
+                if (!findProducerConnectionsForGroup(adminExt, topic, 
group).isEmpty()) {
+                    scopedGroups.add(group);
+                }
+            } catch (Exception e) {
+                log.warn("Failed to verify producer group {} against topic={}, 
skipping: {}",
+                        group, topic, rootMessage(e));
+            }
+        }
+        return scopedGroups;
     }
 
     private ProducerGroupScanResult scanProducerGroups(MQAdminExt adminExt, 
String query, int limit) {
diff --git 
a/server/src/test/java/org/apache/rocketmq/studio/provider/apache/RocketMQClientProviderTest.java
 
b/server/src/test/java/org/apache/rocketmq/studio/provider/apache/RocketMQClientProviderTest.java
index 4cdef3a40..355f39b98 100644
--- 
a/server/src/test/java/org/apache/rocketmq/studio/provider/apache/RocketMQClientProviderTest.java
+++ 
b/server/src/test/java/org/apache/rocketmq/studio/provider/apache/RocketMQClientProviderTest.java
@@ -587,6 +587,46 @@ class RocketMQClientProviderTest {
                 .satisfies(error -> assertThat(((BusinessException) 
error).getCode()).isEqualTo(502));
     }
 
+    @Test
+    void producerGroupSelectorScopesSuggestionsToTheRequestedTopicTest() 
throws Exception {
+        // The selector takes a topic parameter and the very next call examines
+        // (group, topic) connections; a suggestion that never produced to the 
topic yields an
+        // empty connection list, so each candidate must be verified against 
the topic.
+        when(adminExt.examineBrokerClusterInfo()).thenReturn(clusterInfo(
+                "127.0.0.1:10911"));
+        when(adminExt.getAllProducerInfo("127.0.0.1:10911"))
+                .thenReturn(new ProducerTableInfo(Map.of(
+                        "pg-order", List.of(producerInfo("producer-order", 
"10.0.0.1:1000")),
+                        "pg-payment", List.of(producerInfo("producer-payment", 
"10.0.0.2:1000")))));
+        ProducerConnection orderOnTopic = new ProducerConnection();
+        orderOnTopic.setConnectionSet(new HashSet<>(List.of(
+                connection("producer-order", "10.0.0.1:1000"))));
+        when(adminExt.examineProducerConnectionInfo("pg-order", 
"TopicA")).thenReturn(orderOnTopic);
+        when(adminExt.examineProducerConnectionInfo("pg-payment", "TopicA"))
+                .thenThrow(new MQClientException(2003, "Not found the producer 
group connection"));
+
+        List<String> groups = provider.findProducerGroups("instance-a", 
"TopicA", null, 20);
+
+        assertThat(groups).containsExactly("pg-order");
+    }
+
+    @Test
+    void producerGroupSelectorKeepsAllMatchesWhenNoTopicIsRequestedTest() 
throws Exception {
+        // Without a topic the selector must keep its cheap whole-broker scan: 
no per-group
+        // connection probing, every producer group is a valid suggestion.
+        when(adminExt.examineBrokerClusterInfo()).thenReturn(clusterInfo(
+                "127.0.0.1:10911"));
+        when(adminExt.getAllProducerInfo("127.0.0.1:10911"))
+                .thenReturn(new ProducerTableInfo(Map.of(
+                        "pg-order", List.of(producerInfo("producer-order", 
"10.0.0.1:1000")),
+                        "pg-payment", List.of(producerInfo("producer-payment", 
"10.0.0.2:1000")))));
+
+        List<String> groups = provider.findProducerGroups("instance-a", null, 
"pg", 20);
+
+        assertThat(groups).containsExactly("pg-order", "pg-payment");
+        verify(adminExt, never()).examineProducerConnectionInfo(anyString(), 
anyString());
+    }
+
     @Test
     void producerGroupSelectorReturnsSortedUniqueBoundedMatches() throws 
Exception {
         when(adminExt.examineBrokerClusterInfo()).thenReturn(clusterInfo(
@@ -601,7 +641,7 @@ class RocketMQClientProviderTest {
                         "pg-shipment", 
List.of(producerInfo("producer-shipment", "10.0.0.4:1000")),
                         " ", List.of(producerInfo("ignored", 
"10.0.0.5:1000")))));
 
-        List<String> groups = provider.findProducerGroups("instance-a", 
"TopicA", "pg", 2);
+        List<String> groups = provider.findProducerGroups("instance-a", null, 
"pg", 2);
 
         assertThat(groups).containsExactly("pg-order", "pg-payment");
         verify(adminExt, never()).examineProducerConnectionInfo(anyString(), 
anyString());
@@ -630,7 +670,7 @@ class RocketMQClientProviderTest {
                 .thenReturn(new ProducerTableInfo(Map.of(
                         "pg-payment", List.of(producerInfo("producer-payment", 
"10.0.0.2:1000")))));
 
-        List<String> groups = provider.findProducerGroups("instance-a", 
"TopicA", "pg", 20);
+        List<String> groups = provider.findProducerGroups("instance-a", null, 
"pg", 20);
 
         assertThat(groups).containsExactly("pg-payment");
     }

Reply via email to