Search in sources :

Example 1 with QueryConsumerOffsetResponseHeader

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

the class MQClientAPIImpl method queryConsumerOffset.

public long queryConsumerOffset(final String addr, final QueryConsumerOffsetRequestHeader requestHeader, final long timeoutMillis) throws RemotingException, MQBrokerException, InterruptedException {
    RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.QUERY_CONSUMER_OFFSET, requestHeader);
    RemotingCommand response = this.remotingClient.invokeSync(MixAll.brokerVIPChannel(this.clientConfig.isVipChannelEnabled(), addr), request, timeoutMillis);
    assert response != null;
    switch(response.getCode()) {
        case ResponseCode.SUCCESS:
            {
                QueryConsumerOffsetResponseHeader responseHeader = (QueryConsumerOffsetResponseHeader) response.decodeCommandCustomHeader(QueryConsumerOffsetResponseHeader.class);
                return responseHeader.getOffset();
            }
        default:
            break;
    }
    throw new MQBrokerException(response.getCode(), response.getRemark());
}
Also used : RemotingCommand(org.apache.rocketmq.remoting.protocol.RemotingCommand) QueryConsumerOffsetResponseHeader(org.apache.rocketmq.common.protocol.header.QueryConsumerOffsetResponseHeader) MQBrokerException(org.apache.rocketmq.client.exception.MQBrokerException)

Example 2 with QueryConsumerOffsetResponseHeader

use of org.apache.rocketmq.common.protocol.header.QueryConsumerOffsetResponseHeader 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 3 with QueryConsumerOffsetResponseHeader

use of org.apache.rocketmq.common.protocol.header.QueryConsumerOffsetResponseHeader 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)

Example 4 with QueryConsumerOffsetResponseHeader

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

the class MQClientAPIImpl method queryConsumerOffset.

public // 
long queryConsumerOffset(// 
final String addr, // 
final QueryConsumerOffsetRequestHeader requestHeader, // 
final long timeoutMillis) throws RemotingException, MQBrokerException, InterruptedException {
    RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.QUERY_CONSUMER_OFFSET, requestHeader);
    RemotingCommand response = this.remotingClient.invokeSync(MixAll.brokerVIPChannel(this.clientConfig.isVipChannelEnabled(), addr), request, timeoutMillis);
    assert response != null;
    switch(response.getCode()) {
        case ResponseCode.SUCCESS:
            {
                QueryConsumerOffsetResponseHeader responseHeader = (QueryConsumerOffsetResponseHeader) response.decodeCommandCustomHeader(QueryConsumerOffsetResponseHeader.class);
                return responseHeader.getOffset();
            }
        default:
            break;
    }
    throw new MQBrokerException(response.getCode(), response.getRemark());
}
Also used : RemotingCommand(org.apache.rocketmq.remoting.protocol.RemotingCommand) QueryConsumerOffsetResponseHeader(org.apache.rocketmq.common.protocol.header.QueryConsumerOffsetResponseHeader) MQBrokerException(org.apache.rocketmq.client.exception.MQBrokerException)

Aggregations

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