Confluent-kafka-go: Read array of messages kafka consumer

Created on 15 Jun 2020  路  2Comments  路  Source: confluentinc/confluent-kafka-go

I want to read batch of messages as following code works in java.

```try {
while (true) { 1
ConsumerRecords records = consumer.poll(100);
for (ConsumerRecord record : records)
{
log.debug("topic = %s, partition = %d, offset = %d,"
customer = %s, country = %s\n",
record.topic(), record.partition(), record.offset(),
record.key(), record.value());

        int updatedCount = 1;
        if (custCountryMap.countainsKey(record.value())) {
            updatedCount = custCountryMap.get(record.value()) + 1;
        }
        custCountryMap.put(record.value(), updatedCount)

        JSONObject json = new JSONObject(custCountryMap);
        System.out.println(json.toString(4)) 
    }
}

} finally {
consumer.close();
}
```

Is this possible in go?

question

Most helpful comment

no - messages are delivered to your application one at a time.

note: behind the scenes, librdkafka is pulling messages from the brokers in batches in background threads and, with the default settings, buffers them aggressively - so performance is great. the one-at-a-time API is better for every use case we could thought of (is higher level).

All 2 comments

no - messages are delivered to your application one at a time.

note: behind the scenes, librdkafka is pulling messages from the brokers in batches in background threads and, with the default settings, buffers them aggressively - so performance is great. the one-at-a-time API is better for every use case we could thought of (is higher level).

Any usecase which requires batch processing would require to reimplement batch processing. Writing data to database. Applying ML models on GPU. Etc.

Was this page helpful?
0 / 5 - 0 ratings