You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@kafka.apache.org by Guozhang Wang <wa...@gmail.com> on 2015/04/06 23:28:06 UTC

Re: Java NPE in using KafkaConsumer API

Hi Sandeep / Alec,

I have been testing on trunk's KafkaConsumer with partition subscription
only, and it works for me. The topic subscription does not work yet as we
are still implementing that feature.

Could you confirm if you are using trunk's KafkaConsumer and subscribe to
partitions?

Guozhang

On Mon, Mar 30, 2015 at 9:24 AM, Jay Kreps <ja...@gmail.com> wrote:

> Are you using the 0.8.2 release or trunk?
>
> -Jay
>
> On Mon, Mar 30, 2015 at 1:35 AM, Sandeep Bishnoi <
> sandeepbishnoi.bits@gmail.com> wrote:
>
> > Hi,
> >
> >  I have configured a kafka consumer as follows:
> >     Properties props = new Properties();
> >      // ......
> >      // Populated properties
> >     KafkaConsumer consumer = new KafkaConsumer(props);
> >
> >     // subscribe to partition "0" of topic test
> >     TopicPartition partition0 = new TopicPartition("test", 0);
> >     TopicPartition[] partitions = new TopicPartition[1];
> >     partitions[0] = partition0;
> >     consumer.subscribe(partitions);
> >     System.out.println("Created consumer " + consumer);
> >
> >   Consumer is getting created without any errors.
> >
> >  Now I am following instructions on how to read from a partition using
> >
> >
> http://kafka.apache.org/083/javadoc/org/apache/kafka/clients/consumer/KafkaConsumer.html
> > .
> >
> >  Here is a code snippet for the same:
> >
> >     boolean isRunning = true;
> >     Map<TopicPartition, Long> consumedOffsets = new
> HashMap<TopicPartition,
> > Long>();
> >     while(isRunning)
> >     {
> >       Map<String, ConsumerRecords<byte[], byte[]>> records =
> > consumer.poll(100);
> >      .......
> >      .....
> >
> >   The consumer.poll() api is returning null always. Although the
> remaining
> > code is based on the returned value from poll.
> >
> >   Can you please let me know whether
> > org.apache.kafka.clients.consumer.KafkaConsumer is a valid API to use if
> I
> > want to create a client which can read from a given partition of a given
> > topic.
> >
> > Best Regards,
> > Sandeep
> >
>



-- 
-- Guozhang