Ratha

It appears you have couple of issues here, so I’ll start with the consumer 
first.
If you do a search on this mailing list on “Consumer deadlock” in the subject 
you’ll find a thread where similar symptoms were discussed. Basically the 
hasNext() method you mentioned is implemented as a blocking call and while we 
may all have opinion about that decision and why Iterator was chosen in the 
first place, it is what it is. But from what I understand it simply means that 
there are no messages to poll from the topic (yes I know, hasNext()=false seems 
natural here but. . .). What you can do is set ‘consumer.timeout.ms’ property 
to value such as ‘1’. By doing so you are stating that you are willing to block 
for no longer then 1 millisecond.
But you also mention that you are sending message to the topic and therefore 
have reasonable expectation to poll something from it but yet you’re blocking. 
That is strange indeed. What I would suggest is to try one thing at the time. 
Use your Java producer, in conjunction with console consumer. This will help to 
narrow down the problem (e.g., issue with producer that may not be actually 
sending). Then hopefully if you receive successfully then you know the problem 
is in the consumer and so on.

Cheers
Oleg

On Mar 29, 2016, at 12:48 AM, Ratha v 
<vijayara...@gmail.com<mailto:vijayara...@gmail.com>> wrote:

Hi all;
I publish a java object and try to consume it..
I have a poll method to consume objects, but it never returns any
objects..My program runs forever.(?)

*ConsumerThread*

public void run() {

try {

consumer.subscribe(topics);


Iterator<ConsumerRecord<String, File>> it = consumer.poll(1000).iterator();

while (it.hasNext()) {

ConsumerRecord<String, File> record = it.next();

FileProcessor processor = new FileProcessor();

processor.processFile(record.value());

System.out.println("-----" + ": " + record);



When i debug it never goes inside the while loop. Why is that?

I publish object like this;

producer.send(new ProducerRecord<String, File>(topic, file));


Thanks
--
-Ratha
http://vvratha.blogspot.com/

Reply via email to