You can use the --list (List all available topics)for option to kafka-topics.shsee if self.topicthe array exists topics, as shown below.
, , . , --describe (List details for the given topics), , . , , (--describe), , , .
wanted_topics = ['host_updates_queue', 'foo_bar']
topics = subprocess.check_output([os.path.join(KAFKABIN, 'kafka-topics.sh'),
'--list',
'--zookeeper', '{}:2181'.format(KAFKAHOST)])
for wanted in wanted_topics:
if wanted in topics:
print '\'{}\' topic exists!'.format(wanted)
else:
print '\'{}\' topic does NOT exist!'.format(wanted)
topic_desc = subprocess.check_output([os.path.join(KAFKABIN, 'kafka-topics.sh'),
'--describe',
'--topic', wanted,
'--zookeeper', '{}:2181'.format(KAFKAHOST)])
if not topic_desc:
print 'No description found for the topic \'{}\''.format(wanted)
:
root@dev:/opt/kafka/kafka_2.10-0.8.2.1
'host_updates_queue' topic exists!
'foo_bar' topic does NOT exist!
No description found for the topic 'foo_bar'
, :
auto.create.topics.enable | true | . true, .
, .
, (server.properties) num.partitions default.replication.factor, .