Search in sources :

Example 6 with GroupList

use of org.apache.rocketmq.common.protocol.body.GroupList in project rocketmq-externals by apache.

the class ConsumerServiceImpl method queryConsumeStatsListByTopicName.

@Override
@MultiMQAdminCmdMethod
public Map<String, /*groupName*/
TopicConsumerInfo> queryConsumeStatsListByTopicName(String topic) {
    Map<String, TopicConsumerInfo> group2ConsumerInfoMap = Maps.newHashMap();
    try {
        GroupList groupList = mqAdminExt.queryTopicConsumeByWho(topic);
        for (String group : groupList.getGroupList()) {
            List<TopicConsumerInfo> topicConsumerInfoList = null;
            try {
                topicConsumerInfoList = queryConsumeStatsList(topic, group);
            } catch (Exception ignore) {
            }
            group2ConsumerInfoMap.put(group, CollectionUtils.isEmpty(topicConsumerInfoList) ? new TopicConsumerInfo(topic) : topicConsumerInfoList.get(0));
        }
        return group2ConsumerInfoMap;
    } catch (Exception e) {
        throw propagate(e);
    }
}
Also used : GroupList(org.apache.rocketmq.common.protocol.body.GroupList) TopicConsumerInfo(org.apache.rocketmq.console.model.TopicConsumerInfo) MQClientException(org.apache.rocketmq.client.exception.MQClientException) MultiMQAdminCmdMethod(org.apache.rocketmq.console.aspect.admin.annotation.MultiMQAdminCmdMethod)

Example 7 with GroupList

use of org.apache.rocketmq.common.protocol.body.GroupList in project rocketmq-externals by apache.

the class DashboardCollectTask method collectTopic.

@Scheduled(cron = "30 0/1 * * * ?")
@MultiMQAdminCmdMethod(timeoutMillis = 5000)
public void collectTopic() {
    if (!rmqConfigure.isEnableDashBoardCollect()) {
        return;
    }
    Date date = new Date();
    Stopwatch stopwatch = Stopwatch.createStarted();
    try {
        TopicList topicList = mqAdminExt.fetchAllTopicList();
        Set<String> topicSet = topicList.getTopicList();
        for (String topic : topicSet) {
            if (topic.startsWith(MixAll.RETRY_GROUP_TOPIC_PREFIX) || topic.startsWith(MixAll.DLQ_GROUP_TOPIC_PREFIX)) {
                continue;
            }
            TopicRouteData topicRouteData = mqAdminExt.examineTopicRouteInfo(topic);
            GroupList groupList = mqAdminExt.queryTopicConsumeByWho(topic);
            double inTPS = 0;
            long inMsgCntToday = 0;
            double outTPS = 0;
            long outMsgCntToday = 0;
            for (BrokerData bd : topicRouteData.getBrokerDatas()) {
                String masterAddr = bd.getBrokerAddrs().get(MixAll.MASTER_ID);
                if (masterAddr != null) {
                    try {
                        stopwatch.start();
                        log.info("start time: {}", stopwatch.toString());
                        BrokerStatsData bsd = mqAdminExt.viewBrokerStatsData(masterAddr, BrokerStatsManager.TOPIC_PUT_NUMS, topic);
                        stopwatch.stop();
                        log.info("stop time : {}", stopwatch.toString());
                        stopwatch.reset();
                        inTPS += bsd.getStatsMinute().getTps();
                        inMsgCntToday += StatsAllSubCommand.compute24HourSum(bsd);
                    } catch (Exception e) {
                    // throw Throwables.propagate(e);
                    }
                }
            }
            if (groupList != null && !groupList.getGroupList().isEmpty()) {
                for (String group : groupList.getGroupList()) {
                    for (BrokerData bd : topicRouteData.getBrokerDatas()) {
                        String masterAddr = bd.getBrokerAddrs().get(MixAll.MASTER_ID);
                        if (masterAddr != null) {
                            try {
                                String statsKey = String.format("%s@%s", topic, group);
                                BrokerStatsData bsd = mqAdminExt.viewBrokerStatsData(masterAddr, BrokerStatsManager.GROUP_GET_NUMS, statsKey);
                                outTPS += bsd.getStatsMinute().getTps();
                                outMsgCntToday += StatsAllSubCommand.compute24HourSum(bsd);
                            } catch (Exception e) {
                            // throw Throwables.propagate(e);
                            }
                        }
                    }
                }
            }
            List<String> list;
            try {
                list = dashboardCollectService.getTopicMap().get(topic);
            } catch (ExecutionException e) {
                throw Throwables.propagate(e);
            }
            if (null == list) {
                list = Lists.newArrayList();
            }
            list.add(date.getTime() + "," + new BigDecimal(inTPS).setScale(5, BigDecimal.ROUND_HALF_UP) + "," + inMsgCntToday + "," + new BigDecimal(outTPS).setScale(5, BigDecimal.ROUND_HALF_UP) + "," + outMsgCntToday);
            dashboardCollectService.getTopicMap().put(topic, list);
        }
        log.debug("Topic Collected Data in memory = {}" + JsonUtil.obj2String(dashboardCollectService.getTopicMap().asMap()));
    } catch (Exception err) {
        throw Throwables.propagate(err);
    }
}
Also used : BrokerData(org.apache.rocketmq.common.protocol.route.BrokerData) Stopwatch(com.google.common.base.Stopwatch) Date(java.util.Date) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) BigDecimal(java.math.BigDecimal) TopicRouteData(org.apache.rocketmq.common.protocol.route.TopicRouteData) GroupList(org.apache.rocketmq.common.protocol.body.GroupList) TopicList(org.apache.rocketmq.common.protocol.body.TopicList) ExecutionException(java.util.concurrent.ExecutionException) BrokerStatsData(org.apache.rocketmq.common.protocol.body.BrokerStatsData) Scheduled(org.springframework.scheduling.annotation.Scheduled) MultiMQAdminCmdMethod(org.apache.rocketmq.console.aspect.admin.annotation.MultiMQAdminCmdMethod)

Example 8 with GroupList

use of org.apache.rocketmq.common.protocol.body.GroupList in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.

the class AdminBrokerProcessor method queryTopicConsumeByWho.

private RemotingCommand queryTopicConsumeByWho(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException {
    final RemotingCommand response = RemotingCommand.createResponseCommand(null);
    QueryTopicConsumeByWhoRequestHeader requestHeader = (QueryTopicConsumeByWhoRequestHeader) request.decodeCommandCustomHeader(QueryTopicConsumeByWhoRequestHeader.class);
    HashSet<String> groups = this.brokerController.getConsumerManager().queryTopicConsumeByWho(requestHeader.getTopic());
    Set<String> groupInOffset = this.brokerController.getConsumerOffsetManager().whichGroupByTopic(requestHeader.getTopic());
    if (groupInOffset != null && !groupInOffset.isEmpty()) {
        groups.addAll(groupInOffset);
    }
    GroupList groupList = new GroupList();
    groupList.setGroupList(groups);
    byte[] body = groupList.encode();
    response.setBody(body);
    response.setCode(ResponseCode.SUCCESS);
    response.setRemark(null);
    return response;
}
Also used : RemotingCommand(org.apache.rocketmq.remoting.protocol.RemotingCommand) GroupList(org.apache.rocketmq.common.protocol.body.GroupList) QueryTopicConsumeByWhoRequestHeader(org.apache.rocketmq.common.protocol.header.QueryTopicConsumeByWhoRequestHeader)

Example 9 with GroupList

use of org.apache.rocketmq.common.protocol.body.GroupList in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.

the class DefaultMQAdminExtTest method init.

@BeforeClass
public static void init() throws Exception {
    mQClientAPIImpl = mock(MQClientAPIImpl.class);
    defaultMQAdminExt = new DefaultMQAdminExt();
    defaultMQAdminExtImpl = new DefaultMQAdminExtImpl(defaultMQAdminExt, 1000);
    Field field = DefaultMQAdminExtImpl.class.getDeclaredField("mqClientInstance");
    field.setAccessible(true);
    field.set(defaultMQAdminExtImpl, mqClientInstance);
    field = MQClientInstance.class.getDeclaredField("mQClientAPIImpl");
    field.setAccessible(true);
    field.set(mqClientInstance, mQClientAPIImpl);
    field = DefaultMQAdminExt.class.getDeclaredField("defaultMQAdminExtImpl");
    field.setAccessible(true);
    field.set(defaultMQAdminExt, defaultMQAdminExtImpl);
    properties.setProperty("maxMessageSize", "5000000");
    properties.setProperty("flushDelayOffsetInterval", "15000");
    properties.setProperty("serverSocketRcvBufSize", "655350");
    when(mQClientAPIImpl.getBrokerConfig(anyString(), anyLong())).thenReturn(properties);
    Set<String> topicSet = new HashSet<>();
    topicSet.add("topic_one");
    topicSet.add("topic_two");
    topicList.setTopicList(topicSet);
    when(mQClientAPIImpl.getTopicListFromNameServer(anyLong())).thenReturn(topicList);
    List<BrokerData> brokerDatas = new ArrayList<>();
    HashMap<Long, String> brokerAddrs = new HashMap<>();
    brokerAddrs.put(1234l, "127.0.0.1:10911");
    BrokerData brokerData = new BrokerData();
    brokerData.setCluster("default-cluster");
    brokerData.setBrokerName("default-broker");
    brokerData.setBrokerAddrs(brokerAddrs);
    brokerDatas.add(brokerData);
    topicRouteData.setBrokerDatas(brokerDatas);
    topicRouteData.setQueueDatas(new ArrayList<QueueData>());
    topicRouteData.setFilterServerTable(new HashMap<String, List<String>>());
    when(mQClientAPIImpl.getTopicRouteInfoFromNameServer(anyString(), anyLong())).thenReturn(topicRouteData);
    HashMap<String, String> result = new HashMap<>();
    result.put("id", "1234");
    result.put("brokerName", "default-broker");
    kvTable.setTable(result);
    when(mQClientAPIImpl.getBrokerRuntimeInfo(anyString(), anyLong())).thenReturn(kvTable);
    HashMap<String, BrokerData> brokerAddrTable = new HashMap<>();
    brokerAddrTable.put("default-broker", brokerData);
    brokerAddrTable.put("broker-test", new BrokerData());
    clusterInfo.setBrokerAddrTable(brokerAddrTable);
    clusterInfo.setClusterAddrTable(new HashMap<String, Set<String>>());
    when(mQClientAPIImpl.getBrokerClusterInfo(anyLong())).thenReturn(clusterInfo);
    when(mQClientAPIImpl.cleanExpiredConsumeQueue(anyString(), anyLong())).thenReturn(true);
    Set<String> clusterList = new HashSet<>();
    clusterList.add("default-cluster-one");
    clusterList.add("default-cluster-two");
    when(mQClientAPIImpl.getClusterList(anyString(), anyLong())).thenReturn(clusterList);
    GroupList groupList = new GroupList();
    HashSet<String> groups = new HashSet<>();
    groups.add("consumer-group-one");
    groups.add("consumer-group-two");
    groupList.setGroupList(groups);
    when(mQClientAPIImpl.getTopicRouteInfoFromNameServer(anyString(), anyLong())).thenReturn(topicRouteData);
    when(mQClientAPIImpl.queryTopicConsumeByWho(anyString(), anyString(), anyLong())).thenReturn(groupList);
    SubscriptionGroupWrapper subscriptionGroupWrapper = new SubscriptionGroupWrapper();
    ConcurrentHashMap<String, SubscriptionGroupConfig> subscriptions = new ConcurrentHashMap<>();
    SubscriptionGroupConfig subscriptionGroupConfig = new SubscriptionGroupConfig();
    subscriptionGroupConfig.setConsumeBroadcastEnable(true);
    subscriptionGroupConfig.setBrokerId(1234);
    subscriptionGroupConfig.setGroupName("Consumer-group-one");
    subscriptions.put("Consumer-group-one", subscriptionGroupConfig);
    subscriptionGroupWrapper.setSubscriptionGroupTable(subscriptions);
    when(mQClientAPIImpl.getAllSubscriptionGroup(anyString(), anyLong())).thenReturn(subscriptionGroupWrapper);
    String topicListConfig = "topicListConfig";
    when(mQClientAPIImpl.getKVConfigValue(anyString(), anyString(), anyLong())).thenReturn(topicListConfig);
    KVTable kvTable = new KVTable();
    HashMap<String, String> kv = new HashMap<>();
    kv.put("broker-name", "broker-one");
    kv.put("cluster-name", "default-cluster");
    kvTable.setTable(kv);
    when(mQClientAPIImpl.getKVListByNamespace(anyString(), anyLong())).thenReturn(kvTable);
    ConsumeStats consumeStats = new ConsumeStats();
    consumeStats.setConsumeTps(1234);
    MessageQueue messageQueue = new MessageQueue();
    OffsetWrapper offsetWrapper = new OffsetWrapper();
    HashMap<MessageQueue, OffsetWrapper> stats = new HashMap<>();
    stats.put(messageQueue, offsetWrapper);
    consumeStats.setOffsetTable(stats);
    when(mQClientAPIImpl.getConsumeStats(anyString(), anyString(), anyString(), anyLong())).thenReturn(consumeStats);
    ConsumerConnection consumerConnection = new ConsumerConnection();
    consumerConnection.setConsumeType(ConsumeType.CONSUME_PASSIVELY);
    consumerConnection.setMessageModel(MessageModel.CLUSTERING);
    HashSet<Connection> connections = new HashSet<>();
    connections.add(new Connection());
    consumerConnection.setConnectionSet(connections);
    consumerConnection.setSubscriptionTable(new ConcurrentHashMap<String, SubscriptionData>());
    consumerConnection.setConsumeFromWhere(ConsumeFromWhere.CONSUME_FROM_FIRST_OFFSET);
    when(mQClientAPIImpl.getConsumerConnectionList(anyString(), anyString(), anyLong())).thenReturn(consumerConnection);
    ProducerConnection producerConnection = new ProducerConnection();
    Connection connection = new Connection();
    connection.setClientAddr("127.0.0.1:9898");
    connection.setClientId("PID_12345");
    HashSet<Connection> connectionSet = new HashSet<Connection>();
    connectionSet.add(connection);
    producerConnection.setConnectionSet(connectionSet);
    when(mQClientAPIImpl.getProducerConnectionList(anyString(), anyString(), anyLong())).thenReturn(producerConnection);
    when(mQClientAPIImpl.wipeWritePermOfBroker(anyString(), anyString(), anyLong())).thenReturn(6);
    TopicStatsTable topicStatsTable = new TopicStatsTable();
    topicStatsTable.setOffsetTable(new HashMap<MessageQueue, TopicOffset>());
    Map<String, Map<MessageQueue, Long>> consumerStatus = new HashMap<>();
    when(mQClientAPIImpl.invokeBrokerToGetConsumerStatus(anyString(), anyString(), anyString(), anyString(), anyLong())).thenReturn(consumerStatus);
    List<QueueTimeSpan> queueTimeSpanList = new ArrayList<>();
    when(mQClientAPIImpl.queryConsumeTimeSpan(anyString(), anyString(), anyString(), anyLong())).thenReturn(queueTimeSpanList);
    ConsumerRunningInfo consumerRunningInfo = new ConsumerRunningInfo();
    consumerRunningInfo.setJstack("test");
    consumerRunningInfo.setMqTable(new TreeMap<MessageQueue, ProcessQueueInfo>());
    consumerRunningInfo.setStatusTable(new TreeMap<String, ConsumeStatus>());
    consumerRunningInfo.setSubscriptionSet(new TreeSet<SubscriptionData>());
    when(mQClientAPIImpl.getConsumerRunningInfo(anyString(), anyString(), anyString(), anyBoolean(), anyLong())).thenReturn(consumerRunningInfo);
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) QueueData(org.apache.rocketmq.common.protocol.route.QueueData) ArrayList(java.util.ArrayList) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ProducerConnection(org.apache.rocketmq.common.protocol.body.ProducerConnection) GroupList(org.apache.rocketmq.common.protocol.body.GroupList) TopicStatsTable(org.apache.rocketmq.common.admin.TopicStatsTable) TopicList(org.apache.rocketmq.common.protocol.body.TopicList) GroupList(org.apache.rocketmq.common.protocol.body.GroupList) List(java.util.List) ArrayList(java.util.ArrayList) ConsumeStatsList(org.apache.rocketmq.common.protocol.body.ConsumeStatsList) HashSet(java.util.HashSet) KVTable(org.apache.rocketmq.common.protocol.body.KVTable) ConsumeStats(org.apache.rocketmq.common.admin.ConsumeStats) ConsumerConnection(org.apache.rocketmq.common.protocol.body.ConsumerConnection) ConsumeStatus(org.apache.rocketmq.common.protocol.body.ConsumeStatus) QueueTimeSpan(org.apache.rocketmq.common.protocol.body.QueueTimeSpan) MessageQueue(org.apache.rocketmq.common.message.MessageQueue) ArgumentMatchers.anyLong(org.mockito.ArgumentMatchers.anyLong) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) SubscriptionGroupWrapper(org.apache.rocketmq.common.protocol.body.SubscriptionGroupWrapper) Set(java.util.Set) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) BrokerData(org.apache.rocketmq.common.protocol.route.BrokerData) SubscriptionGroupConfig(org.apache.rocketmq.common.subscription.SubscriptionGroupConfig) OffsetWrapper(org.apache.rocketmq.common.admin.OffsetWrapper) Field(java.lang.reflect.Field) TopicOffset(org.apache.rocketmq.common.admin.TopicOffset) ConsumerRunningInfo(org.apache.rocketmq.common.protocol.body.ConsumerRunningInfo) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ProcessQueueInfo(org.apache.rocketmq.common.protocol.body.ProcessQueueInfo) Connection(org.apache.rocketmq.common.protocol.body.Connection) ConsumerConnection(org.apache.rocketmq.common.protocol.body.ConsumerConnection) ProducerConnection(org.apache.rocketmq.common.protocol.body.ProducerConnection) MQClientAPIImpl(org.apache.rocketmq.client.impl.MQClientAPIImpl) SubscriptionData(org.apache.rocketmq.common.protocol.heartbeat.SubscriptionData) MQClientInstance(org.apache.rocketmq.client.impl.factory.MQClientInstance) BeforeClass(org.junit.BeforeClass)

Example 10 with GroupList

use of org.apache.rocketmq.common.protocol.body.GroupList in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.

the class DefaultMQAdminExtTest method testQueryTopicConsumeByWho.

@Test
public void testQueryTopicConsumeByWho() throws InterruptedException, RemotingException, MQClientException, MQBrokerException {
    GroupList groupList = defaultMQAdminExt.queryTopicConsumeByWho("UnitTest");
    assertThat(groupList.getGroupList().contains("consumer-group-two")).isTrue();
}
Also used : GroupList(org.apache.rocketmq.common.protocol.body.GroupList) Test(org.junit.Test)

Aggregations

GroupList (org.apache.rocketmq.common.protocol.body.GroupList)16 MQClientException (org.apache.rocketmq.client.exception.MQClientException)7 MQBrokerException (org.apache.rocketmq.client.exception.MQBrokerException)6 RemotingException (org.apache.rocketmq.remoting.exception.RemotingException)6 ArrayList (java.util.ArrayList)4 ConsumeStats (org.apache.rocketmq.common.admin.ConsumeStats)4 TopicList (org.apache.rocketmq.common.protocol.body.TopicList)4 QueryTopicConsumeByWhoRequestHeader (org.apache.rocketmq.common.protocol.header.QueryTopicConsumeByWhoRequestHeader)4 BrokerData (org.apache.rocketmq.common.protocol.route.BrokerData)4 RemotingCommand (org.apache.rocketmq.remoting.protocol.RemotingCommand)4 SubCommandException (org.apache.rocketmq.tools.command.SubCommandException)4 BrokerStatsData (org.apache.rocketmq.common.protocol.body.BrokerStatsData)3 ConsumerConnection (org.apache.rocketmq.common.protocol.body.ConsumerConnection)3 SubscriptionData (org.apache.rocketmq.common.protocol.heartbeat.SubscriptionData)3 TopicRouteData (org.apache.rocketmq.common.protocol.route.TopicRouteData)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 Field (java.lang.reflect.Field)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 List (java.util.List)2