本文整理汇总了Java中com.alibaba.rocketmq.common.admin.OffsetWrapper.getConsumerOffset方法的典型用法代码示例。如果您正苦于以下问题:Java OffsetWrapper.getConsumerOffset方法的具体用法?Java OffsetWrapper.getConsumerOffset怎么用?Java OffsetWrapper.getConsumerOffset使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.alibaba.rocketmq.common.admin.OffsetWrapper
的用法示例。
在下文中一共展示了OffsetWrapper.getConsumerOffset方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: computeUndoneMsgs
import com.alibaba.rocketmq.common.admin.OffsetWrapper; //导入方法依赖的package包/类
private void computeUndoneMsgs(final UndoneMsgs undoneMsgs, final ConsumeStats consumeStats) {
long total = 0;
long singleMax = 0;
long delayMax = 0;
Iterator<Entry<MessageQueue, OffsetWrapper>> it = consumeStats.getOffsetTable().entrySet().iterator();
while (it.hasNext()) {
Entry<MessageQueue, OffsetWrapper> next = it.next();
MessageQueue mq = next.getKey();
OffsetWrapper ow = next.getValue();
long diff = ow.getBrokerOffset() - ow.getConsumerOffset();
if (diff > singleMax) {
singleMax = diff;
}
if (diff > 0) {
total += diff;
}
// Delay
if (ow.getLastTimestamp() > 0) {
try {
long maxOffset = this.defaultMQPullConsumer.maxOffset(mq);
if (maxOffset > 0) {
PullResult pull = this.defaultMQPullConsumer.pull(mq, "*", maxOffset - 1, 1);
switch (pull.getPullStatus()) {
case FOUND:
long delay =
pull.getMsgFoundList().get(0).getStoreTimestamp() - ow.getLastTimestamp();
if (delay > delayMax) {
delayMax = delay;
}
break;
case NO_MATCHED_MSG:
case NO_NEW_MSG:
case OFFSET_ILLEGAL:
break;
default:
break;
}
}
}
catch (Exception e) {
}
}
}
undoneMsgs.setUndoneMsgsTotal(total);
undoneMsgs.setUndoneMsgsSingleMQ(singleMax);
undoneMsgs.setUndoneMsgsDelayTimeMills(delayMax);
}
示例2: resetOffsetByTimestampOld
import com.alibaba.rocketmq.common.admin.OffsetWrapper; //导入方法依赖的package包/类
@Override
public List<RollbackStats> resetOffsetByTimestampOld(String consumerGroup, String topic, long timestamp,
boolean force) throws RemotingException, MQBrokerException, InterruptedException,
MQClientException {
TopicRouteData topicRouteData = this.examineTopicRouteInfo(topic);
List<RollbackStats> rollbackStatsList = new ArrayList<RollbackStats>();
for (BrokerData bd : topicRouteData.getBrokerDatas()) {
String addr = bd.selectBrokerAddr();
if (addr != null) {
// 根据 consumerGroup 查找对应的 mq
ConsumeStats consumeStats =
this.mQClientFactory.getMQClientAPIImpl().getConsumeStats(addr, consumerGroup, 3000);
// 根据 topic 过滤不需要的 mq
for (Map.Entry<MessageQueue, OffsetWrapper> entry : consumeStats.getOffsetTable().entrySet()) {
MessageQueue queue = entry.getKey();
OffsetWrapper offsetWrapper = entry.getValue();
if (topic.equals(queue.getTopic())) {
// 根据 timestamp 查找对应的offset
long offset =
this.mQClientFactory.getMQClientAPIImpl().searchOffset(addr, topic,
queue.getQueueId(), timestamp, 3000);
// 构建按时间回溯消费进度
RollbackStats rollbackStats = new RollbackStats();
rollbackStats.setBrokerName(bd.getBrokerName());
rollbackStats.setQueueId(queue.getQueueId());
rollbackStats.setBrokerOffset(offsetWrapper.getBrokerOffset());
rollbackStats.setConsumerOffset(offsetWrapper.getConsumerOffset());
rollbackStats.setTimestampOffset(offset);
rollbackStats.setRollbackOffset(offsetWrapper.getConsumerOffset());
// 更新 offset
if (force || offset <= offsetWrapper.getConsumerOffset()) {
rollbackStats.setRollbackOffset(offset);
UpdateConsumerOffsetRequestHeader requestHeader =
new UpdateConsumerOffsetRequestHeader();
requestHeader.setConsumerGroup(consumerGroup);
requestHeader.setTopic(topic);
requestHeader.setQueueId(queue.getQueueId());
requestHeader.setCommitOffset(offset);
this.mQClientFactory.getMQClientAPIImpl().updateConsumerOffset(addr,
requestHeader, 3000);
}
rollbackStatsList.add(rollbackStats);
}
}
}
}
return rollbackStatsList;
}