PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, September 19, 2022

[FIXED] How to successfully perform poll on second Kafka consumer within the same thread?

 September 19, 2022     apache-kafka, consumer, java, kafka-consumer-api     No comments   

Issue

I have two Kafka consumers, subscribed to different topics and belonging to the same consumer group, having different consumer ids, running in the same thread. They are executing poll sequentially but after the first is done second seems to be stuck in poll. I tried associating them with different consumer groups and that seems to be working but unfortunately, that is not a viable solution for me.

I found this in "Kafka: The Definitive Guide":

You can’t have multiple consumers that belong to the same group in one thread and you can’t have multiple threads safely use the same consumer. One consumer per thread is the rule.

That quote directs me towards some form of thread cooperation due to the specific order of message processing I need to do.

Can someone provide an explanation of why is it necessary to run different consumers belonging to the same consumer group, subscribed to different topics in separate threads?

Thank you.


Solution

Explanation from Kafka users mailing list

Matthias J. Sax: "Why does it block? Well, after the first consumer calls poll(), it will join the group and the group will have 1 member. When the second consumer calls poll() it will try to join the group. The broker side group coordinator knows that was already one consumer in the group and it will wait until the first consumer say "I am still here and still part of the group" -- however, this will never happen, because the first consumer would do this via calling poll(), but it can't, because the second consumer is stuck in its own poll() call to actually join the group. Eventually the first consumer would time out and be remove from the group and the second consumer unblocks (the group has still one member only). Afterward the first consumer will retry to join the group... etc. etc. This ping pong game will continue forever..."



Answered By - 4evertoblerone
Answer Checked By - Willingham (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing