本文整理匯總了Java中org.apache.kafka.clients.consumer.Consumer.seekToEnd方法的典型用法代碼示例。如果您正苦於以下問題:Java Consumer.seekToEnd方法的具體用法?Java Consumer.seekToEnd怎麽用?Java Consumer.seekToEnd使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.kafka.clients.consumer.Consumer
的用法示例。
在下文中一共展示了Consumer.seekToEnd方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: createConsumer
import org.apache.kafka.clients.consumer.Consumer; //導入方法依賴的package包/類
/**
* createConsumer - create a new consumer
* @return
* @throws Exception
*/
private Consumer<String, String> createConsumer() throws Exception {
Properties props = ConfUtils.getProps(CONSUMER_PROPS);
Consumer<String, String> consumer = new KafkaConsumer<>(props);
// Seek to end automatically
List<TopicPartition> pts = topics.stream().map(s -> new TopicPartition(s, 0)).collect(Collectors.toList());
consumer.assign(pts);
if(rollBack==0){
consumer.seekToEnd(pts);
}else{
for (TopicPartition topicPartition : pts) {
consumer.seek(topicPartition, consumer.position(topicPartition)-rollBack);
logger.info("Consumer seeked to -500000 :"+consumer.position(topicPartition));
}
}
return consumer;
}
示例2: createConsumer
import org.apache.kafka.clients.consumer.Consumer; //導入方法依賴的package包/類
/**
* createConsumer - create a new consumer
* @return
* @throws Exception
*/
private Consumer<String, String> createConsumer() throws Exception {
// Seek to end automatically
TopicPartition dataTopicPartition = new TopicPartition(topicName, 0);
List<TopicPartition> topics = Arrays.asList(dataTopicPartition);
Properties props = ConfUtils.getProps(CONSUMER_PROPS);
Consumer<String, String> consumer = new KafkaConsumer<>(props);
consumer.assign(topics);
if(offset == -1){
consumer.seekToEnd(topics);
logger.info("Consumer seek to end");
}else{
consumer.seek(dataTopicPartition, offset);
logger.info(String.format("read changed as offset: %s", consumer.position(dataTopicPartition)));
}
return consumer;
}
示例3: createConsumer
import org.apache.kafka.clients.consumer.Consumer; //導入方法依賴的package包/類
public static Consumer<String, byte[]> createConsumer(Properties props, String subscribeTopic) throws Exception {
TopicPartition topicPartition = new TopicPartition(subscribeTopic, 0);
List<TopicPartition> topicPartitions = Arrays.asList(topicPartition);
Consumer<String, byte[]> consumer = new KafkaConsumer<>(props);
// consumer.subscribe(Arrays.asList(subscribeTopics.split(",")));
consumer.assign(topicPartitions);
// consumer都是在topo啟動時創建。當Topo重啟,目前的策略是對於kafka中未處理的msg放棄。不再消費。所以seek to end。
consumer.seekToEnd(topicPartitions);
return consumer;
}