Search in sources :

Example 1 with QueryConsumeTimeSpanRequestHeader

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

the class MQClientAPIImpl method queryConsumeTimeSpan.

public List<QueueTimeSpan> queryConsumeTimeSpan(final String addr, final String topic, final String group, final long timeoutMillis) throws RemotingConnectException, RemotingSendRequestException, RemotingTimeoutException, InterruptedException, MQBrokerException {
    QueryConsumeTimeSpanRequestHeader requestHeader = new QueryConsumeTimeSpanRequestHeader();
    requestHeader.setTopic(topic);
    requestHeader.setGroup(group);
    RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.QUERY_CONSUME_TIME_SPAN, requestHeader);
    RemotingCommand response = this.remotingClient.invokeSync(MixAll.brokerVIPChannel(this.clientConfig.isVipChannelEnabled(), addr), request, timeoutMillis);
    switch(response.getCode()) {
        case ResponseCode.SUCCESS:
            {
                QueryConsumeTimeSpanBody consumeTimeSpanBody = GroupList.decode(response.getBody(), QueryConsumeTimeSpanBody.class);
                return consumeTimeSpanBody.getConsumeTimeSpanSet();
            }
        default:
            break;
    }
    throw new MQBrokerException(response.getCode(), response.getRemark());
}
Also used : RemotingCommand(org.apache.rocketmq.remoting.protocol.RemotingCommand) QueryConsumeTimeSpanBody(org.apache.rocketmq.common.protocol.body.QueryConsumeTimeSpanBody) MQBrokerException(org.apache.rocketmq.client.exception.MQBrokerException) QueryConsumeTimeSpanRequestHeader(org.apache.rocketmq.common.protocol.header.QueryConsumeTimeSpanRequestHeader)

Example 2 with QueryConsumeTimeSpanRequestHeader

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

the class AdminBrokerProcessor method queryConsumeTimeSpan.

private RemotingCommand queryConsumeTimeSpan(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException {
    final RemotingCommand response = RemotingCommand.createResponseCommand(null);
    QueryConsumeTimeSpanRequestHeader requestHeader = (QueryConsumeTimeSpanRequestHeader) request.decodeCommandCustomHeader(QueryConsumeTimeSpanRequestHeader.class);
    final String topic = requestHeader.getTopic();
    TopicConfig topicConfig = this.brokerController.getTopicConfigManager().selectTopicConfig(topic);
    if (null == topicConfig) {
        response.setCode(ResponseCode.TOPIC_NOT_EXIST);
        response.setRemark("topic[" + topic + "] not exist");
        return response;
    }
    List<QueueTimeSpan> timeSpanSet = new ArrayList<QueueTimeSpan>();
    for (int i = 0; i < topicConfig.getWriteQueueNums(); i++) {
        QueueTimeSpan timeSpan = new QueueTimeSpan();
        MessageQueue mq = new MessageQueue();
        mq.setTopic(topic);
        mq.setBrokerName(this.brokerController.getBrokerConfig().getBrokerName());
        mq.setQueueId(i);
        timeSpan.setMessageQueue(mq);
        long minTime = this.brokerController.getMessageStore().getEarliestMessageTime(topic, i);
        timeSpan.setMinTimeStamp(minTime);
        long max = this.brokerController.getMessageStore().getMaxOffsetInQueue(topic, i);
        long maxTime = this.brokerController.getMessageStore().getMessageStoreTimeStamp(topic, i, max - 1);
        timeSpan.setMaxTimeStamp(maxTime);
        long consumeTime;
        long consumerOffset = this.brokerController.getConsumerOffsetManager().queryOffset(requestHeader.getGroup(), topic, i);
        if (consumerOffset > 0) {
            consumeTime = this.brokerController.getMessageStore().getMessageStoreTimeStamp(topic, i, consumerOffset - 1);
        } else {
            consumeTime = minTime;
        }
        timeSpan.setConsumeTimeStamp(consumeTime);
        long maxBrokerOffset = this.brokerController.getMessageStore().getMaxOffsetInQueue(requestHeader.getTopic(), i);
        if (consumerOffset < maxBrokerOffset) {
            long nextTime = this.brokerController.getMessageStore().getMessageStoreTimeStamp(topic, i, consumerOffset);
            timeSpan.setDelayTime(System.currentTimeMillis() - nextTime);
        }
        timeSpanSet.add(timeSpan);
    }
    QueryConsumeTimeSpanBody queryConsumeTimeSpanBody = new QueryConsumeTimeSpanBody();
    queryConsumeTimeSpanBody.setConsumeTimeSpanSet(timeSpanSet);
    response.setBody(queryConsumeTimeSpanBody.encode());
    response.setCode(ResponseCode.SUCCESS);
    response.setRemark(null);
    return response;
}
Also used : RemotingCommand(org.apache.rocketmq.remoting.protocol.RemotingCommand) QueueTimeSpan(org.apache.rocketmq.common.protocol.body.QueueTimeSpan) MessageQueue(org.apache.rocketmq.common.message.MessageQueue) QueryConsumeTimeSpanBody(org.apache.rocketmq.common.protocol.body.QueryConsumeTimeSpanBody) QueryConsumeTimeSpanRequestHeader(org.apache.rocketmq.common.protocol.header.QueryConsumeTimeSpanRequestHeader) ArrayList(java.util.ArrayList) TopicConfig(org.apache.rocketmq.common.TopicConfig)

Example 3 with QueryConsumeTimeSpanRequestHeader

use of org.apache.rocketmq.common.protocol.header.QueryConsumeTimeSpanRequestHeader in project rocketmq by apache.

the class AdminBrokerProcessor method queryConsumeTimeSpan.

private RemotingCommand queryConsumeTimeSpan(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException {
    final RemotingCommand response = RemotingCommand.createResponseCommand(null);
    QueryConsumeTimeSpanRequestHeader requestHeader = (QueryConsumeTimeSpanRequestHeader) request.decodeCommandCustomHeader(QueryConsumeTimeSpanRequestHeader.class);
    final String topic = requestHeader.getTopic();
    TopicConfig topicConfig = this.brokerController.getTopicConfigManager().selectTopicConfig(topic);
    if (null == topicConfig) {
        response.setCode(ResponseCode.TOPIC_NOT_EXIST);
        response.setRemark("topic[" + topic + "] not exist");
        return response;
    }
    List<QueueTimeSpan> timeSpanSet = new ArrayList<QueueTimeSpan>();
    for (int i = 0; i < topicConfig.getWriteQueueNums(); i++) {
        QueueTimeSpan timeSpan = new QueueTimeSpan();
        MessageQueue mq = new MessageQueue();
        mq.setTopic(topic);
        mq.setBrokerName(this.brokerController.getBrokerConfig().getBrokerName());
        mq.setQueueId(i);
        timeSpan.setMessageQueue(mq);
        long minTime = this.brokerController.getMessageStore().getEarliestMessageTime(topic, i);
        timeSpan.setMinTimeStamp(minTime);
        long max = this.brokerController.getMessageStore().getMaxOffsetInQueue(topic, i);
        long maxTime = this.brokerController.getMessageStore().getMessageStoreTimeStamp(topic, i, max - 1);
        timeSpan.setMaxTimeStamp(maxTime);
        long consumeTime;
        long consumerOffset = this.brokerController.getConsumerOffsetManager().queryOffset(requestHeader.getGroup(), topic, i);
        if (consumerOffset > 0) {
            consumeTime = this.brokerController.getMessageStore().getMessageStoreTimeStamp(topic, i, consumerOffset - 1);
        } else {
            consumeTime = minTime;
        }
        timeSpan.setConsumeTimeStamp(consumeTime);
        long maxBrokerOffset = this.brokerController.getMessageStore().getMaxOffsetInQueue(requestHeader.getTopic(), i);
        if (consumerOffset < maxBrokerOffset) {
            long nextTime = this.brokerController.getMessageStore().getMessageStoreTimeStamp(topic, i, consumerOffset);
            timeSpan.setDelayTime(System.currentTimeMillis() - nextTime);
        }
        timeSpanSet.add(timeSpan);
    }
    QueryConsumeTimeSpanBody queryConsumeTimeSpanBody = new QueryConsumeTimeSpanBody();
    queryConsumeTimeSpanBody.setConsumeTimeSpanSet(timeSpanSet);
    response.setBody(queryConsumeTimeSpanBody.encode());
    response.setCode(ResponseCode.SUCCESS);
    response.setRemark(null);
    return response;
}
Also used : RemotingCommand(org.apache.rocketmq.remoting.protocol.RemotingCommand) QueueTimeSpan(org.apache.rocketmq.common.protocol.body.QueueTimeSpan) MessageQueue(org.apache.rocketmq.common.message.MessageQueue) QueryConsumeTimeSpanBody(org.apache.rocketmq.common.protocol.body.QueryConsumeTimeSpanBody) QueryConsumeTimeSpanRequestHeader(org.apache.rocketmq.common.protocol.header.QueryConsumeTimeSpanRequestHeader) ArrayList(java.util.ArrayList) TopicConfig(org.apache.rocketmq.common.TopicConfig)

Example 4 with QueryConsumeTimeSpanRequestHeader

use of org.apache.rocketmq.common.protocol.header.QueryConsumeTimeSpanRequestHeader in project rocketmq by apache.

the class MQClientAPIImpl method queryConsumeTimeSpan.

public List<QueueTimeSpan> queryConsumeTimeSpan(final String addr, final String topic, final String group, final long timeoutMillis) throws RemotingConnectException, RemotingSendRequestException, RemotingTimeoutException, InterruptedException, MQBrokerException {
    QueryConsumeTimeSpanRequestHeader requestHeader = new QueryConsumeTimeSpanRequestHeader();
    requestHeader.setTopic(topic);
    requestHeader.setGroup(group);
    RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.QUERY_CONSUME_TIME_SPAN, requestHeader);
    RemotingCommand response = this.remotingClient.invokeSync(MixAll.brokerVIPChannel(this.clientConfig.isVipChannelEnabled(), addr), request, timeoutMillis);
    switch(response.getCode()) {
        case ResponseCode.SUCCESS:
            {
                QueryConsumeTimeSpanBody consumeTimeSpanBody = GroupList.decode(response.getBody(), QueryConsumeTimeSpanBody.class);
                return consumeTimeSpanBody.getConsumeTimeSpanSet();
            }
        default:
            break;
    }
    throw new MQBrokerException(response.getCode(), response.getRemark());
}
Also used : RemotingCommand(org.apache.rocketmq.remoting.protocol.RemotingCommand) QueryConsumeTimeSpanBody(org.apache.rocketmq.common.protocol.body.QueryConsumeTimeSpanBody) MQBrokerException(org.apache.rocketmq.client.exception.MQBrokerException) QueryConsumeTimeSpanRequestHeader(org.apache.rocketmq.common.protocol.header.QueryConsumeTimeSpanRequestHeader)

Aggregations

QueryConsumeTimeSpanBody (org.apache.rocketmq.common.protocol.body.QueryConsumeTimeSpanBody)4 QueryConsumeTimeSpanRequestHeader (org.apache.rocketmq.common.protocol.header.QueryConsumeTimeSpanRequestHeader)4 RemotingCommand (org.apache.rocketmq.remoting.protocol.RemotingCommand)4 ArrayList (java.util.ArrayList)2 MQBrokerException (org.apache.rocketmq.client.exception.MQBrokerException)2 TopicConfig (org.apache.rocketmq.common.TopicConfig)2 MessageQueue (org.apache.rocketmq.common.message.MessageQueue)2 QueueTimeSpan (org.apache.rocketmq.common.protocol.body.QueueTimeSpan)2