當前位置: 首頁>>代碼示例>>Java>>正文


Java Consumer.seekToEnd方法代碼示例

本文整理匯總了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;
}
 
開發者ID:BriData,項目名稱:DBus,代碼行數:23,代碼來源:FullPullerPerfChecker.java

示例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;
}
 
開發者ID:BriData,項目名稱:DBus,代碼行數:25,代碼來源:KafkaReader.java

示例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;
}
 
開發者ID:BriData,項目名稱:DBus,代碼行數:11,代碼來源:DbusHelper.java


注:本文中的org.apache.kafka.clients.consumer.Consumer.seekToEnd方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。