本文整理汇总了Java中com.alibaba.rocketmq.client.consumer.DefaultMQPullConsumer.updateConsumeOffset方法的典型用法代码示例。如果您正苦于以下问题:Java DefaultMQPullConsumer.updateConsumeOffset方法的具体用法?Java DefaultMQPullConsumer.updateConsumeOffset怎么用?Java DefaultMQPullConsumer.updateConsumeOffset使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.alibaba.rocketmq.client.consumer.DefaultMQPullConsumer
的用法示例。
在下文中一共展示了DefaultMQPullConsumer.updateConsumeOffset方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: resetOffsetByTimestamp
import com.alibaba.rocketmq.client.consumer.DefaultMQPullConsumer; //导入方法依赖的package包/类
/**
* Reset consumer topic offset according to time
*
* @param messageModel
* which model
* @param instanceName
* which instance
* @param consumerGroup
* consumer group
* @param topic
* topic
* @param timestamp
* time
* @throws Exception
*/
public static void resetOffsetByTimestamp(//
final MessageModel messageModel,//
final String instanceName,//
final String consumerGroup, //
final String topic, //
final long timestamp) throws Exception {
final Logger log = ClientLogger.getLog();
DefaultMQPullConsumer consumer = new DefaultMQPullConsumer(consumerGroup);
consumer.setInstanceName(instanceName);
consumer.setMessageModel(messageModel);
consumer.start();
Set<MessageQueue> mqs = null;
try {
mqs = consumer.fetchSubscribeMessageQueues(topic);
if (mqs != null && !mqs.isEmpty()) {
TreeSet<MessageQueue> mqsNew = new TreeSet<MessageQueue>(mqs);
for (MessageQueue mq : mqsNew) {
long offset = consumer.searchOffset(mq, timestamp);
if (offset >= 0) {
consumer.updateConsumeOffset(mq, offset);
log.info("resetOffsetByTimestamp updateConsumeOffset success, {} {} {}",
consumerGroup, offset, mq);
}
}
}
}
catch (Exception e) {
log.warn("resetOffsetByTimestamp Exception", e);
throw e;
}
finally {
if (mqs != null) {
consumer.getDefaultMQPullConsumerImpl().getOffsetStore().persistAll(mqs);
}
consumer.shutdown();
}
}
示例2: resetOffsetByTimestamp
import com.alibaba.rocketmq.client.consumer.DefaultMQPullConsumer; //导入方法依赖的package包/类
/**
* 根据时间戳来重置一个订阅组的消费进度
*
* @param messageModel
* 广播消费还是集群消费
* @param instanceName
* 实例名称,保持与工作Consumer一致。
* @param consumerGroup
* 订阅组
* @param topic
* topic
* @param timestamp
* 时间戳
* @throws Exception
*/
public static void resetOffsetByTimestamp(//
final MessageModel messageModel,//
final String instanceName,//
final String consumerGroup, //
final String topic, //
final long timestamp) throws Exception {
final Logger log = ClientLogger.getLog();
DefaultMQPullConsumer consumer = new DefaultMQPullConsumer(consumerGroup);
consumer.setInstanceName(instanceName);
consumer.setMessageModel(messageModel);
consumer.start();
Set<MessageQueue> mqs = null;
try {
mqs = consumer.fetchSubscribeMessageQueues(topic);
if (mqs != null && !mqs.isEmpty()) {
TreeSet<MessageQueue> mqsNew = new TreeSet<MessageQueue>(mqs);
for (MessageQueue mq : mqsNew) {
long offset = consumer.searchOffset(mq, timestamp);
if (offset >= 0) {
consumer.updateConsumeOffset(mq, offset);
log.info("resetOffsetByTimestamp updateConsumeOffset success, {} {} {}",
consumerGroup, offset, mq);
}
}
}
}
catch (Exception e) {
log.warn("resetOffsetByTimestamp Exception", e);
throw e;
}
finally {
if (mqs != null) {
consumer.getDefaultMQPullConsumerImpl().getOffsetStore().persistAll(mqs);
}
consumer.shutdown();
}
}
示例3: putMessageQueueOffset
import com.alibaba.rocketmq.client.consumer.DefaultMQPullConsumer; //导入方法依赖的package包/类
private static void putMessageQueueOffset(DefaultMQPullConsumer consumer, MessageQueue mq, long offset)
throws MQClientException {
consumer.updateConsumeOffset(mq, offset);
}