Is it correct to use Java Kafka Consumer without commit operation? The 2019 Stack Overflow Developer Survey Results Are InHow to read data using Kafka Consumer API from beginning?how to commit offset in kafka topic using OffsetCommitRequest?Kafka Consumer - Poll behaviourKafka 0.9: Consume from earliest Kafka offsetConsume messages without committing from Kafka 10 consumerKafka not able to consume without reading from beginning -JavaKafka consumer API is not working properlyConsume all messages on Kafka topic and disconnectSeek operation in KafkaKafkaConsumer position() vs committed()?Kafka Consumer is not working with transactional semantics (isolation.level = read_commited)

Why doesn't UInt have a toDouble()?

Can withdrawing asylum be illegal?

What do hard-Brexiteers want with respect to the Irish border?

APIPA and LAN Broadcast Domain

Button changing its text & action. Good or terrible?

Sums of normal random variables

Dropping list elements from nested list after evaluation

Did Scotland spend $250,000 for the slogan "Welcome to Scotland"?

Mathematics of imaging the black hole

Are there any other methods to apply to solving simultaneous equations?

Keeping a retro style to sci-fi spaceships?

A word that means fill it to the required quantity

What is the meaning of Triage in Cybersec world?

Star Trek - X-shaped Item on Regula/Orbital Office Starbases

How to type this arrow in math mode?

Old scifi movie from the 50s or 60s with men in solid red uniforms who interrogate a spy from the past

Why isn't the circumferential light around the M87 black hole's event horizon symmetric?

Is it possible for absolutely everyone to attain enlightenment?

What to do when moving next to a bird sanctuary with a loosely-domesticated cat?

Using xargs with pdftk

Did any laptop computers have a built-in 5 1/4 inch floppy drive?

Flight paths in orbit around Ceres?

What do these terms in Caesar's Gallic wars mean?

How much of the clove should I use when using big garlic heads?



Is it correct to use Java Kafka Consumer without commit operation?



The 2019 Stack Overflow Developer Survey Results Are InHow to read data using Kafka Consumer API from beginning?how to commit offset in kafka topic using OffsetCommitRequest?Kafka Consumer - Poll behaviourKafka 0.9: Consume from earliest Kafka offsetConsume messages without committing from Kafka 10 consumerKafka not able to consume without reading from beginning -JavaKafka consumer API is not working properlyConsume all messages on Kafka topic and disconnectSeek operation in KafkaKafkaConsumer position() vs committed()?Kafka Consumer is not working with transactional semantics (isolation.level = read_commited)



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















I need to read set of records from start offset to end offset. I use for this purpose dedicated Kafka consumer. I am OK with at least once semantic (in case, if given application instance goes down, and new applications instance re-reads records from that start offset).



So, can I use such code?



private static KafkaConsumer<Long, String> createConsumer() 

final Properties props = new Properties();

props.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, BOOTSTRAP_SERVERS);
props.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "latest");
props.put(ConsumerConfig.ENABLE_AUTO_COMMIT_CONFIG, false);
props.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, LongDeserializer.class.getName());
props.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class.getName());

return new KafkaConsumer<>(props);


public void process()

KafkaConsumer consumer = createConsumer();
TopicPartition topicPartition = new TopicPartition("topic", 2);
consumer.assign(List.of(topicPartition));

long startOffset = 42;
long endOffset = 100;

consumer.seek(topicPartition, startOffset);

boolean isRunning = true;
while (isRunning)
final ConsumerRecords<Long, String> consumerRecords = consumer.poll(1000);

for (ConsumerRecord<Long, String> record : consumerRecords)
if (record.offset() >= endOffset)
isRunning = false;
break;




consumer.close();



So:



  • I have no commit()

  • I disable auto-commit

  • I have no group-id

Is it correct code? Or it has some hidden problems?










share|improve this question






















  • You can, even though it looks like you have wrong technology. What would be wrong with loading those events into a proper DB and reload it on demand? This answer could be interesting as well. There are couple of ways to achieve what you want to do

    – senseiwu
    Mar 20 at 18:55












  • Possible duplicate of How to read data using Kafka Consumer API from beginning?

    – senseiwu
    Mar 20 at 18:58











  • You should also change your code to use props.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest");

    – senseiwu
    Mar 20 at 19:02











  • @senseiwu is props.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest"); more fast?

    – Max
    Mar 20 at 19:06











  • if you don'T add it, then you won't consume from the earliest offset for a new consumer.

    – senseiwu
    Mar 20 at 19:08

















0















I need to read set of records from start offset to end offset. I use for this purpose dedicated Kafka consumer. I am OK with at least once semantic (in case, if given application instance goes down, and new applications instance re-reads records from that start offset).



So, can I use such code?



private static KafkaConsumer<Long, String> createConsumer() 

final Properties props = new Properties();

props.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, BOOTSTRAP_SERVERS);
props.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "latest");
props.put(ConsumerConfig.ENABLE_AUTO_COMMIT_CONFIG, false);
props.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, LongDeserializer.class.getName());
props.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class.getName());

return new KafkaConsumer<>(props);


public void process()

KafkaConsumer consumer = createConsumer();
TopicPartition topicPartition = new TopicPartition("topic", 2);
consumer.assign(List.of(topicPartition));

long startOffset = 42;
long endOffset = 100;

consumer.seek(topicPartition, startOffset);

boolean isRunning = true;
while (isRunning)
final ConsumerRecords<Long, String> consumerRecords = consumer.poll(1000);

for (ConsumerRecord<Long, String> record : consumerRecords)
if (record.offset() >= endOffset)
isRunning = false;
break;




consumer.close();



So:



  • I have no commit()

  • I disable auto-commit

  • I have no group-id

Is it correct code? Or it has some hidden problems?










share|improve this question






















  • You can, even though it looks like you have wrong technology. What would be wrong with loading those events into a proper DB and reload it on demand? This answer could be interesting as well. There are couple of ways to achieve what you want to do

    – senseiwu
    Mar 20 at 18:55












  • Possible duplicate of How to read data using Kafka Consumer API from beginning?

    – senseiwu
    Mar 20 at 18:58











  • You should also change your code to use props.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest");

    – senseiwu
    Mar 20 at 19:02











  • @senseiwu is props.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest"); more fast?

    – Max
    Mar 20 at 19:06











  • if you don'T add it, then you won't consume from the earliest offset for a new consumer.

    – senseiwu
    Mar 20 at 19:08













0












0








0


0






I need to read set of records from start offset to end offset. I use for this purpose dedicated Kafka consumer. I am OK with at least once semantic (in case, if given application instance goes down, and new applications instance re-reads records from that start offset).



So, can I use such code?



private static KafkaConsumer<Long, String> createConsumer() 

final Properties props = new Properties();

props.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, BOOTSTRAP_SERVERS);
props.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "latest");
props.put(ConsumerConfig.ENABLE_AUTO_COMMIT_CONFIG, false);
props.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, LongDeserializer.class.getName());
props.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class.getName());

return new KafkaConsumer<>(props);


public void process()

KafkaConsumer consumer = createConsumer();
TopicPartition topicPartition = new TopicPartition("topic", 2);
consumer.assign(List.of(topicPartition));

long startOffset = 42;
long endOffset = 100;

consumer.seek(topicPartition, startOffset);

boolean isRunning = true;
while (isRunning)
final ConsumerRecords<Long, String> consumerRecords = consumer.poll(1000);

for (ConsumerRecord<Long, String> record : consumerRecords)
if (record.offset() >= endOffset)
isRunning = false;
break;




consumer.close();



So:



  • I have no commit()

  • I disable auto-commit

  • I have no group-id

Is it correct code? Or it has some hidden problems?










share|improve this question














I need to read set of records from start offset to end offset. I use for this purpose dedicated Kafka consumer. I am OK with at least once semantic (in case, if given application instance goes down, and new applications instance re-reads records from that start offset).



So, can I use such code?



private static KafkaConsumer<Long, String> createConsumer() 

final Properties props = new Properties();

props.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, BOOTSTRAP_SERVERS);
props.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "latest");
props.put(ConsumerConfig.ENABLE_AUTO_COMMIT_CONFIG, false);
props.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, LongDeserializer.class.getName());
props.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class.getName());

return new KafkaConsumer<>(props);


public void process()

KafkaConsumer consumer = createConsumer();
TopicPartition topicPartition = new TopicPartition("topic", 2);
consumer.assign(List.of(topicPartition));

long startOffset = 42;
long endOffset = 100;

consumer.seek(topicPartition, startOffset);

boolean isRunning = true;
while (isRunning)
final ConsumerRecords<Long, String> consumerRecords = consumer.poll(1000);

for (ConsumerRecord<Long, String> record : consumerRecords)
if (record.offset() >= endOffset)
isRunning = false;
break;




consumer.close();



So:



  • I have no commit()

  • I disable auto-commit

  • I have no group-id

Is it correct code? Or it has some hidden problems?







java apache-kafka kafka-consumer-api






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 20 at 17:37









MaxMax

479519




479519












  • You can, even though it looks like you have wrong technology. What would be wrong with loading those events into a proper DB and reload it on demand? This answer could be interesting as well. There are couple of ways to achieve what you want to do

    – senseiwu
    Mar 20 at 18:55












  • Possible duplicate of How to read data using Kafka Consumer API from beginning?

    – senseiwu
    Mar 20 at 18:58











  • You should also change your code to use props.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest");

    – senseiwu
    Mar 20 at 19:02











  • @senseiwu is props.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest"); more fast?

    – Max
    Mar 20 at 19:06











  • if you don'T add it, then you won't consume from the earliest offset for a new consumer.

    – senseiwu
    Mar 20 at 19:08

















  • You can, even though it looks like you have wrong technology. What would be wrong with loading those events into a proper DB and reload it on demand? This answer could be interesting as well. There are couple of ways to achieve what you want to do

    – senseiwu
    Mar 20 at 18:55












  • Possible duplicate of How to read data using Kafka Consumer API from beginning?

    – senseiwu
    Mar 20 at 18:58











  • You should also change your code to use props.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest");

    – senseiwu
    Mar 20 at 19:02











  • @senseiwu is props.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest"); more fast?

    – Max
    Mar 20 at 19:06











  • if you don'T add it, then you won't consume from the earliest offset for a new consumer.

    – senseiwu
    Mar 20 at 19:08
















You can, even though it looks like you have wrong technology. What would be wrong with loading those events into a proper DB and reload it on demand? This answer could be interesting as well. There are couple of ways to achieve what you want to do

– senseiwu
Mar 20 at 18:55






You can, even though it looks like you have wrong technology. What would be wrong with loading those events into a proper DB and reload it on demand? This answer could be interesting as well. There are couple of ways to achieve what you want to do

– senseiwu
Mar 20 at 18:55














Possible duplicate of How to read data using Kafka Consumer API from beginning?

– senseiwu
Mar 20 at 18:58





Possible duplicate of How to read data using Kafka Consumer API from beginning?

– senseiwu
Mar 20 at 18:58













You should also change your code to use props.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest");

– senseiwu
Mar 20 at 19:02





You should also change your code to use props.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest");

– senseiwu
Mar 20 at 19:02













@senseiwu is props.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest"); more fast?

– Max
Mar 20 at 19:06





@senseiwu is props.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest"); more fast?

– Max
Mar 20 at 19:06













if you don'T add it, then you won't consume from the earliest offset for a new consumer.

– senseiwu
Mar 20 at 19:08





if you don'T add it, then you won't consume from the earliest offset for a new consumer.

– senseiwu
Mar 20 at 19:08












1 Answer
1






active

oldest

votes


















1














Yes, it is correct usage, and you shouldn't run into any issues. It's not typical usage of a Kafka consumer, but it is allowed.



From the official KafkaConsumer javadoc (my highlights):



https://kafka.apache.org/21/javadoc/org/apache/kafka/clients/consumer/KafkaConsumer.html




Controlling The Consumer's Position



In most use cases the consumer will simply consume records from beginning to end, periodically committing its position (either automatically or manually). However Kafka allows the consumer to manually control its position, moving forward or backwards in a partition at will. This means a consumer can re-consume older records, or skip to the most recent records without actually consuming the intermediate records.
There are several instances where manually controlling the consumer's position can be useful.



...



Kafka allows specifying the position using seek(TopicPartition, long) to specify the new position. Special methods for seeking to the earliest and latest offset the server maintains are also available ( seekToBeginning(Collection) and seekToEnd(Collection) respectively).







share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55267019%2fis-it-correct-to-use-java-kafka-consumer-without-commit-operation%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    Yes, it is correct usage, and you shouldn't run into any issues. It's not typical usage of a Kafka consumer, but it is allowed.



    From the official KafkaConsumer javadoc (my highlights):



    https://kafka.apache.org/21/javadoc/org/apache/kafka/clients/consumer/KafkaConsumer.html




    Controlling The Consumer's Position



    In most use cases the consumer will simply consume records from beginning to end, periodically committing its position (either automatically or manually). However Kafka allows the consumer to manually control its position, moving forward or backwards in a partition at will. This means a consumer can re-consume older records, or skip to the most recent records without actually consuming the intermediate records.
    There are several instances where manually controlling the consumer's position can be useful.



    ...



    Kafka allows specifying the position using seek(TopicPartition, long) to specify the new position. Special methods for seeking to the earliest and latest offset the server maintains are also available ( seekToBeginning(Collection) and seekToEnd(Collection) respectively).







    share|improve this answer



























      1














      Yes, it is correct usage, and you shouldn't run into any issues. It's not typical usage of a Kafka consumer, but it is allowed.



      From the official KafkaConsumer javadoc (my highlights):



      https://kafka.apache.org/21/javadoc/org/apache/kafka/clients/consumer/KafkaConsumer.html




      Controlling The Consumer's Position



      In most use cases the consumer will simply consume records from beginning to end, periodically committing its position (either automatically or manually). However Kafka allows the consumer to manually control its position, moving forward or backwards in a partition at will. This means a consumer can re-consume older records, or skip to the most recent records without actually consuming the intermediate records.
      There are several instances where manually controlling the consumer's position can be useful.



      ...



      Kafka allows specifying the position using seek(TopicPartition, long) to specify the new position. Special methods for seeking to the earliest and latest offset the server maintains are also available ( seekToBeginning(Collection) and seekToEnd(Collection) respectively).







      share|improve this answer

























        1












        1








        1







        Yes, it is correct usage, and you shouldn't run into any issues. It's not typical usage of a Kafka consumer, but it is allowed.



        From the official KafkaConsumer javadoc (my highlights):



        https://kafka.apache.org/21/javadoc/org/apache/kafka/clients/consumer/KafkaConsumer.html




        Controlling The Consumer's Position



        In most use cases the consumer will simply consume records from beginning to end, periodically committing its position (either automatically or manually). However Kafka allows the consumer to manually control its position, moving forward or backwards in a partition at will. This means a consumer can re-consume older records, or skip to the most recent records without actually consuming the intermediate records.
        There are several instances where manually controlling the consumer's position can be useful.



        ...



        Kafka allows specifying the position using seek(TopicPartition, long) to specify the new position. Special methods for seeking to the earliest and latest offset the server maintains are also available ( seekToBeginning(Collection) and seekToEnd(Collection) respectively).







        share|improve this answer













        Yes, it is correct usage, and you shouldn't run into any issues. It's not typical usage of a Kafka consumer, but it is allowed.



        From the official KafkaConsumer javadoc (my highlights):



        https://kafka.apache.org/21/javadoc/org/apache/kafka/clients/consumer/KafkaConsumer.html




        Controlling The Consumer's Position



        In most use cases the consumer will simply consume records from beginning to end, periodically committing its position (either automatically or manually). However Kafka allows the consumer to manually control its position, moving forward or backwards in a partition at will. This means a consumer can re-consume older records, or skip to the most recent records without actually consuming the intermediate records.
        There are several instances where manually controlling the consumer's position can be useful.



        ...



        Kafka allows specifying the position using seek(TopicPartition, long) to specify the new position. Special methods for seeking to the earliest and latest offset the server maintains are also available ( seekToBeginning(Collection) and seekToEnd(Collection) respectively).








        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 22 at 4:10









        mjuarezmjuarez

        10.5k73954




        10.5k73954





























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55267019%2fis-it-correct-to-use-java-kafka-consumer-without-commit-operation%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

            용인 삼성생명 블루밍스 목차 통계 역대 감독 선수단 응원단 경기장 같이 보기 외부 링크 둘러보기 메뉴samsungblueminx.comeh선수 명단용인 삼성생명 블루밍스용인 삼성생명 블루밍스ehsamsungblueminx.comeheheheh

            155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해