Search in sources :

Example 1 with SearchOffsetResponseHeader

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

the class MQClientAPIImpl method searchOffset.

public long searchOffset(final String addr, final String topic, final int queueId, final long timestamp, final long timeoutMillis) throws RemotingException, MQBrokerException, InterruptedException {
    // 封装头信息
    SearchOffsetRequestHeader requestHeader = new SearchOffsetRequestHeader();
    requestHeader.setTopic(topic);
    requestHeader.setQueueId(queueId);
    requestHeader.setTimestamp(timestamp);
    RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.SEARCH_OFFSET_BY_TIMESTAMP, requestHeader);
    RemotingCommand response = this.remotingClient.invokeSync(MixAll.brokerVIPChannel(this.clientConfig.isVipChannelEnabled(), addr), request, timeoutMillis);
    assert response != null;
    switch(response.getCode()) {
        case ResponseCode.SUCCESS:
            {
                SearchOffsetResponseHeader responseHeader = (SearchOffsetResponseHeader) response.decodeCommandCustomHeader(SearchOffsetResponseHeader.class);
                return responseHeader.getOffset();
            }
        default:
            break;
    }
    throw new MQBrokerException(response.getCode(), response.getRemark());
}
Also used : RemotingCommand(org.apache.rocketmq.remoting.protocol.RemotingCommand) SearchOffsetRequestHeader(org.apache.rocketmq.common.protocol.header.SearchOffsetRequestHeader) MQBrokerException(org.apache.rocketmq.client.exception.MQBrokerException) SearchOffsetResponseHeader(org.apache.rocketmq.common.protocol.header.SearchOffsetResponseHeader)

Example 2 with SearchOffsetResponseHeader

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

the class AdminBrokerProcessor method searchOffsetByTimestamp.

private RemotingCommand searchOffsetByTimestamp(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException {
    final RemotingCommand response = RemotingCommand.createResponseCommand(SearchOffsetResponseHeader.class);
    final SearchOffsetResponseHeader responseHeader = (SearchOffsetResponseHeader) response.readCustomHeader();
    final SearchOffsetRequestHeader requestHeader = (SearchOffsetRequestHeader) request.decodeCommandCustomHeader(SearchOffsetRequestHeader.class);
    // 通过时间得到offset
    long offset = this.brokerController.getMessageStore().getOffsetInQueueByTime(requestHeader.getTopic(), requestHeader.getQueueId(), requestHeader.getTimestamp());
    responseHeader.setOffset(offset);
    response.setCode(ResponseCode.SUCCESS);
    response.setRemark(null);
    return response;
}
Also used : RemotingCommand(org.apache.rocketmq.remoting.protocol.RemotingCommand) SearchOffsetRequestHeader(org.apache.rocketmq.common.protocol.header.SearchOffsetRequestHeader) SearchOffsetResponseHeader(org.apache.rocketmq.common.protocol.header.SearchOffsetResponseHeader)

Example 3 with SearchOffsetResponseHeader

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

the class AdminBrokerProcessor method searchOffsetByTimestamp.

private RemotingCommand searchOffsetByTimestamp(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException {
    final RemotingCommand response = RemotingCommand.createResponseCommand(SearchOffsetResponseHeader.class);
    final SearchOffsetResponseHeader responseHeader = (SearchOffsetResponseHeader) response.readCustomHeader();
    final SearchOffsetRequestHeader requestHeader = (SearchOffsetRequestHeader) request.decodeCommandCustomHeader(SearchOffsetRequestHeader.class);
    long offset = this.brokerController.getMessageStore().getOffsetInQueueByTime(requestHeader.getTopic(), requestHeader.getQueueId(), requestHeader.getTimestamp());
    responseHeader.setOffset(offset);
    response.setCode(ResponseCode.SUCCESS);
    response.setRemark(null);
    return response;
}
Also used : RemotingCommand(org.apache.rocketmq.remoting.protocol.RemotingCommand) SearchOffsetRequestHeader(org.apache.rocketmq.common.protocol.header.SearchOffsetRequestHeader) SearchOffsetResponseHeader(org.apache.rocketmq.common.protocol.header.SearchOffsetResponseHeader)

Example 4 with SearchOffsetResponseHeader

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

the class MQClientAPIImpl method searchOffset.

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

Aggregations

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