それは最善の解決策ではないのですが、誰も答えを持っていると思わないので、私は最後(消費者にグループを割り当てて交換___YOURGROUP____)でそれを解決する方法を、ここにある:
import subprocess
import os
if "KAFKA_HOME" in os.environ:
kafkapath = os.environ["KAFKA_HOME"]
else:
kafkapath = oms_cfg.kafka_home
# error("Please set up $KAFKA_HOME environment variable")
# exit(-1)
instances = []
# cmd = kafkapath + '/bin/kafka-consumer-groups.sh --new-consumer --bootstrap-server {} --list'.format(oms_cfg.bootstrap_servers)
# result = subprocess.run(cmd.split(' '), stdout=subprocess.PIPE, stderr=subprocess.PIPE)
igr = ____YOURGROUP_____ # or run over all groups from the commented out command
print("Checking topics of consumer group {}".format(igr))
topic_cmd = kafkapath + '/bin/kafka-consumer-groups.sh --new-consumer --bootstrap-server ' + oms_cfg.bootstrap_servers + ' --describe --group {gr}'
result = subprocess.run(topic_cmd.format(gr=igr).split(' '), stdout=subprocess.PIPE, stderr=subprocess.PIPE)
table = result.stdout.split(b'\n')
# You could add a loop over topic here
for iline in table[1:]:
iline = iline.split()
if not len(iline):
continue
topic = iline[0]
# we could check here for the topic. multiple consumers in same group -> only one will connect to each topic
# if topic != oms_cfg.topic_in:
# continue
client = iline[-1]
instances.append(tuple([client, topic]))
# print("Client {} Topic {} is fine".format(client, topic))
if len(instances):
error("Cannot start. There are currently {} instances running. Client/topic {}".format(len(instances),
instances))
exit(-1)
これは残念ながら "新しいスタイル"のコンシューマでは機能しません。リストは空です。 –
このリストは空ですか?消費者または消費者団体? @コリン-SBI – shakeel