JaskeyLam
JaskeyLam

Reputation: 15755

How to know which queue is allocated to which consumer-RocketMQ?

Consumer queues are allocated in client side, broker knows nothing about this.

So how can we monitor which queue is allocated to which consumer client?

Upvotes: 0

Views: 237

Answers (1)

Li Zhanhui
Li Zhanhui

Reputation: 61

Though there is no exiting command, for each message queue per consumer group, You can find out the client using provided admin infrastructure. Here is the snippet achieving this:

private Map<MessageQueue, String> getClientConnection(DefaultMQAdminExt defaultMQAdminExt, String groupName){
    Map<MessageQueue, String> results = new HashMap<MessageQueue, String>();
    try{
        ConsumerConnection consumerConnection = defaultMQAdminExt.examineConsumerConnectionInfo(groupName);
        for (Connection connection : consumerConnection.getConnectionSet()){
            String clinetId = connection.getClientId();
            ConsumerRunningInfo consumerRunningInfo = defaultMQAdminExt.getConsumerRunningInfo(groupName, clinetId, false);
            for(MessageQueue messageQueue : consumerRunningInfo.getMqTable().keySet()){
                results.put(messageQueue, clinetId + " " + connection.getClientAddr());
            }
        }
    }catch (Exception e){

    }
    return results;
}

In case you have not used the RocketMQ-Console project, please try and run it: https://github.com/rocketmq/rocketmq-console-ng

In the Consumer tab, Click "consumer detail" button, you will see message queue allocation result visually as below: Message queues allocation result

Upvotes: 1

Related Questions