You need to define msg as MessageAndMetadata<byte[], byte[]>. Thanks,
Jun On Mon, Nov 17, 2014 at 10:43 PM, kade...@yahoo.com.INVALID < kade...@yahoo.com.invalid> wrote: > Hi, > > I am trying to learn more on Kafka consuming patterns if we have > partitions on the topic and testing few scenarios. I would like to print > the message when the consumer consumes along with the partition id. How to > get this done ? > > We have simple consumer code (high level) > > public void run() { > ConsumerIterator<byte[], byte[]> it = m_stream.iterator(); > while (it.hasNext()) > System.out.println("Thread " + m_threadNumber + ": > " + new String(it.next().message())); > System.out.println("Shutting down Thread: " + m_threadNumber); > } > > How to print the message as well as partition id ? > > Tried to assign it.next() to MessageandMetadata variable and printed > partition id (which is declared as int). But while printing message() - it > is declared as object in MessageandMetadata. Message is getting printed as > junk data > > Tried this: > > MessageandMetadata msg; > msg = it.next() > System.out.println("Partition "+ msg.partition() + "Message data" + > msg.message().tostring()); > > Here msg.message() is not printing string value. > Can anyone help on this. > > Kader . > > Sent from Yahoo Mail on Android > >