Search in sources :

Example 1 with ConsumeQueue

use of org.apache.rocketmq.store.ConsumeQueue 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)

Example 2 with ConsumeQueue

use of org.apache.rocketmq.store.ConsumeQueue 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)

Aggregations

ArrayList (java.util.ArrayList)2 ConsumerFilterData (org.apache.rocketmq.broker.filter.ConsumerFilterData)2 ExpressionMessageFilter (org.apache.rocketmq.broker.filter.ExpressionMessageFilter)2 ConsumeQueueData (org.apache.rocketmq.common.protocol.body.ConsumeQueueData)2 QueryConsumeQueueResponseBody (org.apache.rocketmq.common.protocol.body.QueryConsumeQueueResponseBody)2 QueryConsumeQueueRequestHeader (org.apache.rocketmq.common.protocol.header.QueryConsumeQueueRequestHeader)2 SubscriptionData (org.apache.rocketmq.common.protocol.heartbeat.SubscriptionData)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