當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。