How to get of consumer.id which are listening to a topic using Confluent_Kafka?
I am able to get the consumer-groups and topic. But not the consumer name/id.
How to get of consumer.id which are listening to a topic using Confluent_Kafka?
I am able to get the consumer-groups and topic. But not the consumer name/id.
If your consumers are using group functionality, you can get a list of the consumer groups using the AdminClient
and then find each consumer that is a member of the group. it has been added in this commit.
Example snippet
from confluent_kafka.admin import AdminClient
broker = '1.1.1.1:9092' # replace appropriately
a = AdminClient({'bootstrap.servers': broker})
groups = a.list_groups(timeout=10)
print(" {} consumer groups".format(len(groups)))
for g in groups:
print(" \"{}\" with {} member(s), protocol: {}, protocol_type: {}".format(
g, len(g.members), g.protocol, g.protocol_type))
for m in g.members:
print("id {} client_id: {} client_host: {}".format(m.id, m.client_id, m.client_host))
You may be interested in the client_id
field that would differentiate the consumers in a group.
Reference: https://github.com/confluentinc/confluent-kafka-python/blob/master/examples/adminapi.py