Search in sources :

Example 1 with QueryConsumeQueueResponseBody

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

the class QueryConsumeQueueCommand method execute.

@Override
public void execute(CommandLine commandLine, Options options, RPCHook rpcHook) {
    DefaultMQAdminExt defaultMQAdminExt = new DefaultMQAdminExt(rpcHook);
    defaultMQAdminExt.setInstanceName(Long.toString(System.currentTimeMillis()));
    try {
        defaultMQAdminExt.start();
        String topic = commandLine.getOptionValue("t").trim();
        int queueId = Integer.valueOf(commandLine.getOptionValue("q").trim());
        long index = Long.valueOf(commandLine.getOptionValue("i").trim());
        int count = Integer.valueOf(commandLine.getOptionValue("c", "10").trim());
        String broker = null;
        if (commandLine.hasOption("b")) {
            broker = commandLine.getOptionValue("b").trim();
        }
        String consumerGroup = null;
        if (commandLine.hasOption("g")) {
            consumerGroup = commandLine.getOptionValue("g").trim();
        }
        if (broker == null || broker == "") {
            TopicRouteData topicRouteData = defaultMQAdminExt.examineTopicRouteInfo(topic);
            if (topicRouteData == null || topicRouteData.getBrokerDatas() == null || topicRouteData.getBrokerDatas().isEmpty()) {
                throw new Exception("No topic route data!");
            }
            broker = topicRouteData.getBrokerDatas().get(0).getBrokerAddrs().get(0L);
        }
        QueryConsumeQueueResponseBody queryConsumeQueueResponseBody = defaultMQAdminExt.queryConsumeQueue(broker, topic, queueId, index, count, consumerGroup);
        if (queryConsumeQueueResponseBody.getSubscriptionData() != null) {
            System.out.printf("Subscription data: \n%s\n", JSON.toJSONString(queryConsumeQueueResponseBody.getSubscriptionData(), true));
            System.out.print("======================================\n");
        }
        if (queryConsumeQueueResponseBody.getFilterData() != null) {
            System.out.printf("Filter data: \n%s\n", queryConsumeQueueResponseBody.getFilterData());
            System.out.print("======================================\n");
        }
        System.out.printf("Queue data: \nmax: %d, min: %d\n", queryConsumeQueueResponseBody.getMaxQueueIndex(), queryConsumeQueueResponseBody.getMinQueueIndex());
        System.out.print("======================================\n");
        if (queryConsumeQueueResponseBody.getQueueData() != null) {
            long i = index;
            for (ConsumeQueueData queueData : queryConsumeQueueResponseBody.getQueueData()) {
                StringBuilder stringBuilder = new StringBuilder();
                stringBuilder.append("idx: " + i + "\n");
                stringBuilder.append(queueData.toString() + "\n");
                stringBuilder.append("======================================\n");
                System.out.print(stringBuilder.toString());
                i++;
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        defaultMQAdminExt.shutdown();
    }
}
Also used : ConsumeQueueData(org.apache.rocketmq.common.protocol.body.ConsumeQueueData) QueryConsumeQueueResponseBody(org.apache.rocketmq.common.protocol.body.QueryConsumeQueueResponseBody) DefaultMQAdminExt(org.apache.rocketmq.tools.admin.DefaultMQAdminExt) TopicRouteData(org.apache.rocketmq.common.protocol.route.TopicRouteData)

Example 2 with QueryConsumeQueueResponseBody

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

the class AdminBrokerProcessor method queryConsumeQueue.

private RemotingCommand queryConsumeQueue(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException {
    QueryConsumeQueueRequestHeader requestHeader = (QueryConsumeQueueRequestHeader) request.decodeCommandCustomHeader(QueryConsumeQueueRequestHeader.class);
    RemotingCommand response = RemotingCommand.createResponseCommand(null);
    ConsumeQueue consumeQueue = this.brokerController.getMessageStore().getConsumeQueue(requestHeader.getTopic(), requestHeader.getQueueId());
    if (consumeQueue == null) {
        response.setCode(ResponseCode.SYSTEM_ERROR);
        response.setRemark(String.format("%d@%s is not exist!", requestHeader.getQueueId(), requestHeader.getTopic()));
        return response;
    }
    QueryConsumeQueueResponseBody body = new QueryConsumeQueueResponseBody();
    response.setCode(ResponseCode.SUCCESS);
    response.setBody(body.encode());
    body.setMaxQueueIndex(consumeQueue.getMaxOffsetInQueue());
    body.setMinQueueIndex(consumeQueue.getMinOffsetInQueue());
    MessageFilter messageFilter = null;
    if (requestHeader.getConsumerGroup() != null) {
        SubscriptionData subscriptionData = this.brokerController.getConsumerManager().findSubscriptionData(requestHeader.getConsumerGroup(), requestHeader.getTopic());
        body.setSubscriptionData(subscriptionData);
        if (subscriptionData == null) {
            body.setFilterData(String.format("%s@%s is not online!", requestHeader.getConsumerGroup(), requestHeader.getTopic()));
        } else {
            ConsumerFilterData filterData = this.brokerController.getConsumerFilterManager().get(requestHeader.getTopic(), requestHeader.getConsumerGroup());
            body.setFilterData(JSON.toJSONString(filterData, true));
            messageFilter = new ExpressionMessageFilter(subscriptionData, filterData, this.brokerController.getConsumerFilterManager());
        }
    }
    SelectMappedBufferResult result = consumeQueue.getIndexBuffer(requestHeader.getIndex());
    if (result == null) {
        response.setRemark(String.format("Index %d of %d@%s is not exist!", requestHeader.getIndex(), requestHeader.getQueueId(), requestHeader.getTopic()));
        return response;
    }
    try {
        List<ConsumeQueueData> queues = new ArrayList<>();
        for (int i = 0; i < result.getSize() && i < requestHeader.getCount() * ConsumeQueue.CQ_STORE_UNIT_SIZE; i += ConsumeQueue.CQ_STORE_UNIT_SIZE) {
            ConsumeQueueData one = new ConsumeQueueData();
            one.setPhysicOffset(result.getByteBuffer().getLong());
            one.setPhysicSize(result.getByteBuffer().getInt());
            one.setTagsCode(result.getByteBuffer().getLong());
            if (!consumeQueue.isExtAddr(one.getTagsCode())) {
                queues.add(one);
                continue;
            }
            ConsumeQueueExt.CqExtUnit cqExtUnit = consumeQueue.getExt(one.getTagsCode());
            if (cqExtUnit != null) {
                one.setExtendDataJson(JSON.toJSONString(cqExtUnit));
                if (cqExtUnit.getFilterBitMap() != null) {
                    one.setBitMap(BitsArray.create(cqExtUnit.getFilterBitMap()).toString());
                }
                if (messageFilter != null) {
                    one.setEval(messageFilter.isMatchedByConsumeQueue(cqExtUnit.getTagsCode(), cqExtUnit));
                }
            } else {
                one.setMsg("Cq extend not exist!addr: " + one.getTagsCode());
            }
            queues.add(one);
        }
        body.setQueueData(queues);
    } finally {
        result.release();
    }
    return response;
}
Also used : ConsumeQueueData(org.apache.rocketmq.common.protocol.body.ConsumeQueueData) ConsumeQueueExt(org.apache.rocketmq.store.ConsumeQueueExt) QueryConsumeQueueResponseBody(org.apache.rocketmq.common.protocol.body.QueryConsumeQueueResponseBody) ExpressionMessageFilter(org.apache.rocketmq.broker.filter.ExpressionMessageFilter) ArrayList(java.util.ArrayList) SelectMappedBufferResult(org.apache.rocketmq.store.SelectMappedBufferResult) QueryConsumeQueueRequestHeader(org.apache.rocketmq.common.protocol.header.QueryConsumeQueueRequestHeader) RemotingCommand(org.apache.rocketmq.remoting.protocol.RemotingCommand) SubscriptionData(org.apache.rocketmq.common.protocol.heartbeat.SubscriptionData) ConsumerFilterData(org.apache.rocketmq.broker.filter.ConsumerFilterData) MessageFilter(org.apache.rocketmq.store.MessageFilter) ExpressionMessageFilter(org.apache.rocketmq.broker.filter.ExpressionMessageFilter) ConsumeQueue(org.apache.rocketmq.store.ConsumeQueue)

Example 3 with QueryConsumeQueueResponseBody

use of org.apache.rocketmq.common.protocol.body.QueryConsumeQueueResponseBody in project rocketmq by apache.

the class QueryConsumeQueueCommand method execute.

@Override
public void execute(CommandLine commandLine, Options options, RPCHook rpcHook) {
    DefaultMQAdminExt defaultMQAdminExt = new DefaultMQAdminExt(rpcHook);
    defaultMQAdminExt.setInstanceName(Long.toString(System.currentTimeMillis()));
    try {
        defaultMQAdminExt.start();
        String topic = commandLine.getOptionValue("t").trim();
        int queueId = Integer.valueOf(commandLine.getOptionValue("q").trim());
        long index = Long.valueOf(commandLine.getOptionValue("i").trim());
        int count = Integer.valueOf(commandLine.getOptionValue("c", "10").trim());
        String broker = null;
        if (commandLine.hasOption("b")) {
            broker = commandLine.getOptionValue("b").trim();
        }
        String consumerGroup = null;
        if (commandLine.hasOption("g")) {
            consumerGroup = commandLine.getOptionValue("g").trim();
        }
        if (broker == null || broker == "") {
            TopicRouteData topicRouteData = defaultMQAdminExt.examineTopicRouteInfo(topic);
            if (topicRouteData == null || topicRouteData.getBrokerDatas() == null || topicRouteData.getBrokerDatas().isEmpty()) {
                throw new Exception("No topic route data!");
            }
            broker = topicRouteData.getBrokerDatas().get(0).getBrokerAddrs().get(0L);
        }
        QueryConsumeQueueResponseBody queryConsumeQueueResponseBody = defaultMQAdminExt.queryConsumeQueue(broker, topic, queueId, index, count, consumerGroup);
        if (queryConsumeQueueResponseBody.getSubscriptionData() != null) {
            System.out.printf("Subscription data: \n%s\n", JSON.toJSONString(queryConsumeQueueResponseBody.getSubscriptionData(), true));
            System.out.print("======================================\n");
        }
        if (queryConsumeQueueResponseBody.getFilterData() != null) {
            System.out.printf("Filter data: \n%s\n", queryConsumeQueueResponseBody.getFilterData());
            System.out.print("======================================\n");
        }
        System.out.printf("Queue data: \nmax: %d, min: %d\n", queryConsumeQueueResponseBody.getMaxQueueIndex(), queryConsumeQueueResponseBody.getMinQueueIndex());
        System.out.print("======================================\n");
        if (queryConsumeQueueResponseBody.getQueueData() != null) {
            long i = index;
            for (ConsumeQueueData queueData : queryConsumeQueueResponseBody.getQueueData()) {
                StringBuilder stringBuilder = new StringBuilder();
                stringBuilder.append("idx: " + i + "\n");
                stringBuilder.append(queueData.toString() + "\n");
                stringBuilder.append("======================================\n");
                System.out.print(stringBuilder.toString());
                i++;
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        defaultMQAdminExt.shutdown();
    }
}
Also used : ConsumeQueueData(org.apache.rocketmq.common.protocol.body.ConsumeQueueData) QueryConsumeQueueResponseBody(org.apache.rocketmq.common.protocol.body.QueryConsumeQueueResponseBody) DefaultMQAdminExt(org.apache.rocketmq.tools.admin.DefaultMQAdminExt) TopicRouteData(org.apache.rocketmq.common.protocol.route.TopicRouteData)

Example 4 with QueryConsumeQueueResponseBody

use of org.apache.rocketmq.common.protocol.body.QueryConsumeQueueResponseBody in project rocketmq by apache.

the class AdminBrokerProcessor method queryConsumeQueue.

private RemotingCommand queryConsumeQueue(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException {
    QueryConsumeQueueRequestHeader requestHeader = (QueryConsumeQueueRequestHeader) request.decodeCommandCustomHeader(QueryConsumeQueueRequestHeader.class);
    RemotingCommand response = RemotingCommand.createResponseCommand(null);
    ConsumeQueue consumeQueue = this.brokerController.getMessageStore().getConsumeQueue(requestHeader.getTopic(), requestHeader.getQueueId());
    if (consumeQueue == null) {
        response.setCode(ResponseCode.SYSTEM_ERROR);
        response.setRemark(String.format("%d@%s is not exist!", requestHeader.getQueueId(), requestHeader.getTopic()));
        return response;
    }
    QueryConsumeQueueResponseBody body = new QueryConsumeQueueResponseBody();
    response.setCode(ResponseCode.SUCCESS);
    response.setBody(body.encode());
    body.setMaxQueueIndex(consumeQueue.getMaxOffsetInQueue());
    body.setMinQueueIndex(consumeQueue.getMinOffsetInQueue());
    MessageFilter messageFilter = null;
    if (requestHeader.getConsumerGroup() != null) {
        SubscriptionData subscriptionData = this.brokerController.getConsumerManager().findSubscriptionData(requestHeader.getConsumerGroup(), requestHeader.getTopic());
        body.setSubscriptionData(subscriptionData);
        if (subscriptionData == null) {
            body.setFilterData(String.format("%s@%s is not online!", requestHeader.getConsumerGroup(), requestHeader.getTopic()));
        } else {
            ConsumerFilterData filterData = this.brokerController.getConsumerFilterManager().get(requestHeader.getTopic(), requestHeader.getConsumerGroup());
            body.setFilterData(JSON.toJSONString(filterData, true));
            messageFilter = new ExpressionMessageFilter(subscriptionData, filterData, this.brokerController.getConsumerFilterManager());
        }
    }
    SelectMappedBufferResult result = consumeQueue.getIndexBuffer(requestHeader.getIndex());
    if (result == null) {
        response.setRemark(String.format("Index %d of %d@%s is not exist!", requestHeader.getIndex(), requestHeader.getQueueId(), requestHeader.getTopic()));
        return response;
    }
    try {
        List<ConsumeQueueData> queues = new ArrayList<>();
        for (int i = 0; i < result.getSize() && i < requestHeader.getCount() * ConsumeQueue.CQ_STORE_UNIT_SIZE; i += ConsumeQueue.CQ_STORE_UNIT_SIZE) {
            ConsumeQueueData one = new ConsumeQueueData();
            one.setPhysicOffset(result.getByteBuffer().getLong());
            one.setPhysicSize(result.getByteBuffer().getInt());
            one.setTagsCode(result.getByteBuffer().getLong());
            if (!consumeQueue.isExtAddr(one.getTagsCode())) {
                queues.add(one);
                continue;
            }
            ConsumeQueueExt.CqExtUnit cqExtUnit = consumeQueue.getExt(one.getTagsCode());
            if (cqExtUnit != null) {
                one.setExtendDataJson(JSON.toJSONString(cqExtUnit));
                if (cqExtUnit.getFilterBitMap() != null) {
                    one.setBitMap(BitsArray.create(cqExtUnit.getFilterBitMap()).toString());
                }
                if (messageFilter != null) {
                    one.setEval(messageFilter.isMatchedByConsumeQueue(cqExtUnit.getTagsCode(), cqExtUnit));
                }
            } else {
                one.setMsg("Cq extend not exist!addr: " + one.getTagsCode());
            }
            queues.add(one);
        }
        body.setQueueData(queues);
    } finally {
        result.release();
    }
    return response;
}
Also used : ConsumeQueueData(org.apache.rocketmq.common.protocol.body.ConsumeQueueData) ConsumeQueueExt(org.apache.rocketmq.store.ConsumeQueueExt) QueryConsumeQueueResponseBody(org.apache.rocketmq.common.protocol.body.QueryConsumeQueueResponseBody) ExpressionMessageFilter(org.apache.rocketmq.broker.filter.ExpressionMessageFilter) ArrayList(java.util.ArrayList) SelectMappedBufferResult(org.apache.rocketmq.store.SelectMappedBufferResult) QueryConsumeQueueRequestHeader(org.apache.rocketmq.common.protocol.header.QueryConsumeQueueRequestHeader) RemotingCommand(org.apache.rocketmq.remoting.protocol.RemotingCommand) SubscriptionData(org.apache.rocketmq.common.protocol.heartbeat.SubscriptionData) ConsumerFilterData(org.apache.rocketmq.broker.filter.ConsumerFilterData) MessageFilter(org.apache.rocketmq.store.MessageFilter) ExpressionMessageFilter(org.apache.rocketmq.broker.filter.ExpressionMessageFilter) ConsumeQueue(org.apache.rocketmq.store.ConsumeQueue)

Aggregations

ConsumeQueueData (org.apache.rocketmq.common.protocol.body.ConsumeQueueData)4 QueryConsumeQueueResponseBody (org.apache.rocketmq.common.protocol.body.QueryConsumeQueueResponseBody)4 ArrayList (java.util.ArrayList)2 ConsumerFilterData (org.apache.rocketmq.broker.filter.ConsumerFilterData)2 ExpressionMessageFilter (org.apache.rocketmq.broker.filter.ExpressionMessageFilter)2 QueryConsumeQueueRequestHeader (org.apache.rocketmq.common.protocol.header.QueryConsumeQueueRequestHeader)2 SubscriptionData (org.apache.rocketmq.common.protocol.heartbeat.SubscriptionData)2 TopicRouteData (org.apache.rocketmq.common.protocol.route.TopicRouteData)2 RemotingCommand (org.apache.rocketmq.remoting.protocol.RemotingCommand)2 ConsumeQueue (org.apache.rocketmq.store.ConsumeQueue)2 ConsumeQueueExt (org.apache.rocketmq.store.ConsumeQueueExt)2 MessageFilter (org.apache.rocketmq.store.MessageFilter)2 SelectMappedBufferResult (org.apache.rocketmq.store.SelectMappedBufferResult)2 DefaultMQAdminExt (org.apache.rocketmq.tools.admin.DefaultMQAdminExt)2