Quantcast
Channel: Kafka Timeline
Viewing all articles
Browse latest Browse all 1519

can't iterate consumed messages when checking errorCode first

$
0
0
Hi all,

I'm using Kafka low level consumer api and find in the below codes
"iterator.hasNext" always return false. Through debugging, I'm sure the
messageSet has the size of "fetchSize"

* val consumer = new SimpleConsumer(broker.host, broker.port,
soTimeout, soBufferSize, clientId)*
* val request = new FetchRequestBuilder()*
* .addFetch(topic, partition, offset, fetchSize)*
* .build()*
* val response = consumer.fetch(request)*
* response.errorCode(topic, partition) match {*
* case NoError => {*
* iterator = response.messageSet(topic, partition).iterator*
* }*
* case error => throw exceptionFor(error)*
* }*

The weird thing is that the iterator works fine when I get iterator
directly without checking the error code.

* val consumer = new SimpleConsumer(broker.host, broker.port,
soTimeout, soBufferSize, clientId)*
* val request = new FetchRequestBuilder()*
* .addFetch(topic, partition, offset, fetchSize)*
* .build()*
* consumer.fetch(request).messageSet(topic, partition).iterator*

Any thoughts ?

Thanks,
Manu Zhang

Viewing all articles
Browse latest Browse all 1519

Trending Articles