当前位置: 首页>>代码示例>>Java>>正文


Java QueryConsumerOffsetRequestHeader类代码示例

本文整理汇总了Java中org.apache.rocketmq.common.protocol.header.QueryConsumerOffsetRequestHeader的典型用法代码示例。如果您正苦于以下问题:Java QueryConsumerOffsetRequestHeader类的具体用法?Java QueryConsumerOffsetRequestHeader怎么用?Java QueryConsumerOffsetRequestHeader使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


QueryConsumerOffsetRequestHeader类属于org.apache.rocketmq.common.protocol.header包,在下文中一共展示了QueryConsumerOffsetRequestHeader类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: fetchConsumeOffsetFromBroker

import org.apache.rocketmq.common.protocol.header.QueryConsumerOffsetRequestHeader; //导入依赖的package包/类
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);
    }
}
 
开发者ID:lirenzuo,项目名称:rocketmq-rocketmq-all-4.1.0-incubating,代码行数:22,代码来源:RemoteBrokerOffsetStore.java

示例2: queryConsumerOffset

import org.apache.rocketmq.common.protocol.header.QueryConsumerOffsetRequestHeader; //导入依赖的package包/类
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());
}
 
开发者ID:lirenzuo,项目名称:rocketmq-rocketmq-all-4.1.0-incubating,代码行数:24,代码来源:MQClientAPIImpl.java

示例3: fetchConsumeOffsetFromBroker

import org.apache.rocketmq.common.protocol.header.QueryConsumerOffsetRequestHeader; //导入依赖的package包/类
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);
    }
}
 
开发者ID:apache,项目名称:rocketmq,代码行数:22,代码来源:RemoteBrokerOffsetStore.java

示例4: queryConsumerOffset

import org.apache.rocketmq.common.protocol.header.QueryConsumerOffsetRequestHeader; //导入依赖的package包/类
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());
}
 
开发者ID:apache,项目名称:rocketmq,代码行数:24,代码来源:MQClientAPIImpl.java

示例5: testReadOffset_WithException

import org.apache.rocketmq.common.protocol.header.QueryConsumerOffsetRequestHeader; //导入依赖的package包/类
@Test
public void testReadOffset_WithException() throws Exception {
    OffsetStore offsetStore = new RemoteBrokerOffsetStore(mQClientFactory, group);
    MessageQueue messageQueue = new MessageQueue(topic, brokerName, 2);

    offsetStore.updateOffset(messageQueue, 1024, false);

    doThrow(new MQBrokerException(-1, ""))
        .when(mqClientAPI).queryConsumerOffset(anyString(), any(QueryConsumerOffsetRequestHeader.class), anyLong());
    assertThat(offsetStore.readOffset(messageQueue, ReadOffsetType.READ_FROM_STORE)).isEqualTo(-1);

    doThrow(new RemotingException("", null))
        .when(mqClientAPI).queryConsumerOffset(anyString(), any(QueryConsumerOffsetRequestHeader.class), anyLong());
    assertThat(offsetStore.readOffset(messageQueue, ReadOffsetType.READ_FROM_STORE)).isEqualTo(-2);
}
 
开发者ID:lirenzuo,项目名称:rocketmq-rocketmq-all-4.1.0-incubating,代码行数:16,代码来源:RemoteBrokerOffsetStoreTest.java

示例6: testReadOffset_Success

import org.apache.rocketmq.common.protocol.header.QueryConsumerOffsetRequestHeader; //导入依赖的package包/类
@Test
public void testReadOffset_Success() throws Exception {
    OffsetStore offsetStore = new RemoteBrokerOffsetStore(mQClientFactory, group);
    final MessageQueue messageQueue = new MessageQueue(topic, brokerName, 3);

    doAnswer(new Answer() {
        @Override public Object answer(InvocationOnMock mock) throws Throwable {
            UpdateConsumerOffsetRequestHeader updateRequestHeader = mock.getArgument(1);
            when(mqClientAPI.queryConsumerOffset(anyString(), any(QueryConsumerOffsetRequestHeader.class), anyLong())).thenReturn(updateRequestHeader.getCommitOffset());
            return null;
        }
    }).when(mqClientAPI).updateConsumerOffsetOneway(any(String.class), any(UpdateConsumerOffsetRequestHeader.class), any(Long.class));

    offsetStore.updateOffset(messageQueue, 1024, false);
    offsetStore.persist(messageQueue);
    assertThat(offsetStore.readOffset(messageQueue, ReadOffsetType.READ_FROM_STORE)).isEqualTo(1024);

    offsetStore.updateOffset(messageQueue, 1023, false);
    offsetStore.persist(messageQueue);
    assertThat(offsetStore.readOffset(messageQueue, ReadOffsetType.READ_FROM_STORE)).isEqualTo(1023);

    offsetStore.updateOffset(messageQueue, 1022, true);
    offsetStore.persist(messageQueue);
    assertThat(offsetStore.readOffset(messageQueue, ReadOffsetType.READ_FROM_STORE)).isEqualTo(1023);

    offsetStore.updateOffset(messageQueue, 1025, false);
    offsetStore.persistAll(new HashSet<MessageQueue>(Collections.singletonList(messageQueue)));
    assertThat(offsetStore.readOffset(messageQueue, ReadOffsetType.READ_FROM_STORE)).isEqualTo(1025);
}
 
开发者ID:lirenzuo,项目名称:rocketmq-rocketmq-all-4.1.0-incubating,代码行数:30,代码来源:RemoteBrokerOffsetStoreTest.java

示例7: testReadOffset_Success

import org.apache.rocketmq.common.protocol.header.QueryConsumerOffsetRequestHeader; //导入依赖的package包/类
@Test
public void testReadOffset_Success() throws Exception {
    OffsetStore offsetStore = new RemoteBrokerOffsetStore(mQClientFactory, group);
    final MessageQueue messageQueue = new MessageQueue(topic, brokerName, 3);

    doAnswer(new Answer() {
        @Override public Object answer(InvocationOnMock mock) throws Throwable {
            UpdateConsumerOffsetRequestHeader updateRequestHeader = mock.getArgument(1);
            when(mqClientAPI.queryConsumerOffset(anyString(), any(QueryConsumerOffsetRequestHeader.class), anyLong())).thenReturn(updateRequestHeader.getCommitOffset());
            return null;
        }
    }).when(mqClientAPI).updateConsumerOffsetOneway(any(String.class), any(UpdateConsumerOffsetRequestHeader.class), any(Long.class));

    offsetStore.updateOffset(messageQueue, 1024, false);
    offsetStore.persist(messageQueue);
    assertThat(offsetStore.readOffset(messageQueue, ReadOffsetType.READ_FROM_STORE)).isEqualTo(1024);

    offsetStore.updateOffset(messageQueue, 1023, false);
    offsetStore.persist(messageQueue);
    assertThat(offsetStore.readOffset(messageQueue, ReadOffsetType.READ_FROM_STORE)).isEqualTo(1023);

    offsetStore.updateOffset(messageQueue, 1022, true);
    offsetStore.persist(messageQueue);
    assertThat(offsetStore.readOffset(messageQueue, ReadOffsetType.READ_FROM_STORE)).isEqualTo(1023);

    offsetStore.updateOffset(messageQueue, 1025, false);
    offsetStore.persistAll(new HashSet<>(Collections.singletonList(messageQueue)));
    assertThat(offsetStore.readOffset(messageQueue, ReadOffsetType.READ_FROM_STORE)).isEqualTo(1025);
}
 
开发者ID:lyy4j,项目名称:rmq4note,代码行数:30,代码来源:RemoteBrokerOffsetStoreTest.java

示例8: queryConsumerOffset

import org.apache.rocketmq.common.protocol.header.QueryConsumerOffsetRequestHeader; //导入依赖的package包/类
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().getMinOffsetInQuque(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;
}
 
开发者ID:lyy4j,项目名称:rmq4note,代码行数:37,代码来源:ConsumerManageProcessor.java

示例9: testReadOffset_Success

import org.apache.rocketmq.common.protocol.header.QueryConsumerOffsetRequestHeader; //导入依赖的package包/类
@Test
public void testReadOffset_Success() throws Exception {
    OffsetStore offsetStore = new RemoteBrokerOffsetStore(mQClientFactory, group);
    final MessageQueue messageQueue = new MessageQueue(topic, brokerName, 3);

    doAnswer(new Answer() {
        @Override
        public Object answer(InvocationOnMock mock) throws Throwable {
            UpdateConsumerOffsetRequestHeader updateRequestHeader = mock.getArgument(1);
            when(mqClientAPI.queryConsumerOffset(anyString(), any(QueryConsumerOffsetRequestHeader.class), anyLong())).thenReturn(updateRequestHeader.getCommitOffset());
            return null;
        }
    }).when(mqClientAPI).updateConsumerOffsetOneway(any(String.class), any(UpdateConsumerOffsetRequestHeader.class), any(Long.class));

    offsetStore.updateOffset(messageQueue, 1024, false);
    offsetStore.persist(messageQueue);
    assertThat(offsetStore.readOffset(messageQueue, ReadOffsetType.READ_FROM_STORE)).isEqualTo(1024);

    offsetStore.updateOffset(messageQueue, 1023, false);
    offsetStore.persist(messageQueue);
    assertThat(offsetStore.readOffset(messageQueue, ReadOffsetType.READ_FROM_STORE)).isEqualTo(1023);

    offsetStore.updateOffset(messageQueue, 1022, true);
    offsetStore.persist(messageQueue);
    assertThat(offsetStore.readOffset(messageQueue, ReadOffsetType.READ_FROM_STORE)).isEqualTo(1023);

    offsetStore.updateOffset(messageQueue, 1025, false);
    offsetStore.persistAll(new HashSet<MessageQueue>(Collections.singletonList(messageQueue)));
    assertThat(offsetStore.readOffset(messageQueue, ReadOffsetType.READ_FROM_STORE)).isEqualTo(1025);
}
 
开发者ID:apache,项目名称:rocketmq,代码行数:31,代码来源:RemoteBrokerOffsetStoreTest.java

示例10: queryConsumerOffset

import org.apache.rocketmq.common.protocol.header.QueryConsumerOffsetRequestHeader; //导入依赖的package包/类
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;
}
 
开发者ID:apache,项目名称:rocketmq,代码行数:37,代码来源:ConsumerManageProcessor.java

示例11: queryConsumerOffset

import org.apache.rocketmq.common.protocol.header.QueryConsumerOffsetRequestHeader; //导入依赖的package包/类
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());
        // 订阅组不存在情况下,如果这个队列的消息最小Offset是0,则表示这个Topic上线时间不长,服务器堆积的数据也不多,那么这个订阅组就从0开始消费。
        // 尤其对于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;
}
 
开发者ID:lirenzuo,项目名称:rocketmq-rocketmq-all-4.1.0-incubating,代码行数:44,代码来源:ConsumerManageProcessor.java


注:本文中的org.apache.rocketmq.common.protocol.header.QueryConsumerOffsetRequestHeader类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。