Skip to content
This repository was archived by the owner on Jul 26, 2025. It is now read-only.

consumeStrings() discards buffered messages #53

@martin-frydl

Description

@martin-frydl

When there are multiple messages in topic and consumeStrings() is called with number of messages less than number present in there, the extra messages will be discarded.

Example:

@ClassRule
public static KafkaJunitRule kafka = new KafkaJunitRule(EphemeralKafkaBroker.create()).waitForStartup();

@Test
public void test() throws Exception {
        kafka.helper().produceStrings("test", "a", "b");
        kafka.helper().consumeStrings("test", 1).get();
        kafka.helper().consumeStrings("test", 1).get();
}

Here I send two string messages into topic and then try to read one-by-one using consumeStrings(). The first one will succeed and return "a" while the second one will block forever.

The reason is enable.auto.commit set to true. The consumer will receive both messages in one poll() and commit only one (RecordConsumer.call(), line 311). This is correct but since autocommit is enabled, both message were already committed. The problem is that I'm not able to override properties passed to KafkaConsumer or set autocommit to false in consumerConfig() - as these are both called automatically from consumeStrings().

I think the solution could be to use consumerConfig(false) for creating consumer in consumeStrings(). But I haven't tested it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions