Search in sources :

Example 1 with QueryConsumerOffsetRequestHeader

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

the class ConsumerManageProcessor method queryConsumerOffset.

private RemotingCommand queryConsumerOffset(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException {
    final RemotingCommand response = RemotingCommand.createResponseCommand(QueryConsumerOffsetResponseHeader.class);
    final QueryConsumerOffsetResponseHeader responseHeader = (QueryConsumerOffsetResponseHeader) response.readCustomHeader();
    final QueryConsumerOffsetRequestHeader requestHeader = (QueryConsumerOffsetRequestHeader) request.decodeCommandCustomHeader(QueryConsumerOffsetRequestHeader.class);
    long offset = this.brokerController.getConsumerOffsetManager().queryOffset(requestHeader.getConsumerGroup(), requestHeader.getTopic(), requestHeader.getQueueId());
    // 订阅组存在
    if (offset >= 0) {
        responseHeader.setOffset(offset);
        response.setCode(ResponseCode.SUCCESS);
        response.setRemark(null);
    } else // 订阅组不存在
    {
        long minOffset = this.brokerController.getMessageStore().getMinOffsetInQueue(requestHeader.getTopic(), requestHeader.getQueueId());
        // 尤其对于Topic队列数动态扩容时,必须要从0开始消费。
        if (minOffset <= 0 && !this.brokerController.getMessageStore().checkInDiskByConsumeOffset(requestHeader.getTopic(), requestHeader.getQueueId(), 0)) {
            responseHeader.setOffset(0L);
            response.setCode(ResponseCode.SUCCESS);
            response.setRemark(null);
        } else // 新版本服务器不做消费进度纠正
        {
            response.setCode(ResponseCode.QUERY_NOT_FOUND);
            response.setRemark("Not found, V3_0_6_SNAPSHOT maybe this group consumer boot first");
        }
    }
    return response;
}
Also used : RemotingCommand(org.apache.rocketmq.remoting.protocol.RemotingCommand) QueryConsumerOffsetResponseHeader(org.apache.rocketmq.common.protocol.header.QueryConsumerOffsetResponseHeader) QueryConsumerOffsetRequestHeader(org.apache.rocketmq.common.protocol.header.QueryConsumerOffsetRequestHeader)

Example 2 with QueryConsumerOffsetRequestHeader

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

the class RemoteBrokerOffsetStore method fetchConsumeOffsetFromBroker.

private long fetchConsumeOffsetFromBroker(MessageQueue mq) throws RemotingException, MQBrokerException, InterruptedException, MQClientException {
    FindBrokerResult findBrokerResult = this.mQClientFactory.findBrokerAddressInAdmin(mq.getBrokerName());
    if (null == findBrokerResult) {
        this.mQClientFactory.updateTopicRouteInfoFromNameServer(mq.getTopic());
        findBrokerResult = this.mQClientFactory.findBrokerAddressInAdmin(mq.getBrokerName());
    }
    if (findBrokerResult != null) {
        QueryConsumerOffsetRequestHeader requestHeader = new QueryConsumerOffsetRequestHeader();
        requestHeader.setTopic(mq.getTopic());
        requestHeader.setConsumerGroup(this.groupName);
        requestHeader.setQueueId(mq.getQueueId());
        return this.mQClientFactory.getMQClientAPIImpl().queryConsumerOffset(findBrokerResult.getBrokerAddr(), requestHeader, 1000 * 5);
    } else {
        throw new MQClientException("The broker[" + mq.getBrokerName() + "] not exist", null);
    }
}
Also used : QueryConsumerOffsetRequestHeader(org.apache.rocketmq.common.protocol.header.QueryConsumerOffsetRequestHeader) FindBrokerResult(org.apache.rocketmq.client.impl.FindBrokerResult) MQClientException(org.apache.rocketmq.client.exception.MQClientException)

Example 3 with QueryConsumerOffsetRequestHeader

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

the class RemoteBrokerOffsetStore method fetchConsumeOffsetFromBroker.

// 根据broker name获取broker地址,之后根据topic,group name和queue id获取消费的位置
private long fetchConsumeOffsetFromBroker(MessageQueue mq) throws RemotingException, MQBrokerException, InterruptedException, MQClientException {
    FindBrokerResult findBrokerResult = this.mQClientFactory.findBrokerAddressInAdmin(mq.getBrokerName());
    if (null == findBrokerResult) {
        // TODO Here may be heavily overhead for Name Server,need tuning
        this.mQClientFactory.updateTopicRouteInfoFromNameServer(mq.getTopic());
        findBrokerResult = this.mQClientFactory.findBrokerAddressInAdmin(mq.getBrokerName());
    }
    if (findBrokerResult != null) {
        QueryConsumerOffsetRequestHeader requestHeader = new QueryConsumerOffsetRequestHeader();
        requestHeader.setTopic(mq.getTopic());
        requestHeader.setConsumerGroup(this.groupName);
        requestHeader.setQueueId(mq.getQueueId());
        return this.mQClientFactory.getMQClientAPIImpl().queryConsumerOffset(findBrokerResult.getBrokerAddr(), requestHeader, 1000 * 5);
    } else {
        throw new MQClientException("The broker[" + mq.getBrokerName() + "] not exist", null);
    }
}
Also used : QueryConsumerOffsetRequestHeader(org.apache.rocketmq.common.protocol.header.QueryConsumerOffsetRequestHeader) FindBrokerResult(org.apache.rocketmq.client.impl.FindBrokerResult) MQClientException(org.apache.rocketmq.client.exception.MQClientException)

Example 4 with QueryConsumerOffsetRequestHeader

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

the class ConsumerManageProcessor method queryConsumerOffset.

private RemotingCommand queryConsumerOffset(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException {
    final RemotingCommand response = RemotingCommand.createResponseCommand(QueryConsumerOffsetResponseHeader.class);
    final QueryConsumerOffsetResponseHeader responseHeader = (QueryConsumerOffsetResponseHeader) response.readCustomHeader();
    final QueryConsumerOffsetRequestHeader requestHeader = (QueryConsumerOffsetRequestHeader) request.decodeCommandCustomHeader(QueryConsumerOffsetRequestHeader.class);
    long offset = this.brokerController.getConsumerOffsetManager().queryOffset(requestHeader.getConsumerGroup(), requestHeader.getTopic(), requestHeader.getQueueId());
    if (offset >= 0) {
        responseHeader.setOffset(offset);
        response.setCode(ResponseCode.SUCCESS);
        response.setRemark(null);
    } else {
        long minOffset = this.brokerController.getMessageStore().getMinOffsetInQueue(requestHeader.getTopic(), requestHeader.getQueueId());
        if (minOffset <= 0 && !this.brokerController.getMessageStore().checkInDiskByConsumeOffset(requestHeader.getTopic(), requestHeader.getQueueId(), 0)) {
            responseHeader.setOffset(0L);
            response.setCode(ResponseCode.SUCCESS);
            response.setRemark(null);
        } else {
            response.setCode(ResponseCode.QUERY_NOT_FOUND);
            response.setRemark("Not found, V3_0_6_SNAPSHOT maybe this group consumer boot first");
        }
    }
    return response;
}
Also used : RemotingCommand(org.apache.rocketmq.remoting.protocol.RemotingCommand) QueryConsumerOffsetResponseHeader(org.apache.rocketmq.common.protocol.header.QueryConsumerOffsetResponseHeader) QueryConsumerOffsetRequestHeader(org.apache.rocketmq.common.protocol.header.QueryConsumerOffsetRequestHeader)

Aggregations

QueryConsumerOffsetRequestHeader (org.apache.rocketmq.common.protocol.header.QueryConsumerOffsetRequestHeader)4 MQClientException (org.apache.rocketmq.client.exception.MQClientException)2 FindBrokerResult (org.apache.rocketmq.client.impl.FindBrokerResult)2 QueryConsumerOffsetResponseHeader (org.apache.rocketmq.common.protocol.header.QueryConsumerOffsetResponseHeader)2 RemotingCommand (org.apache.rocketmq.remoting.protocol.RemotingCommand)2