@@ -177,18 +177,22 @@ c.close()
177
177
Create topics:
178
178
179
179
``` python
180
- new_topics = [NewTopic(topic, num_partitions = 3 , replication_factor = 1 ) for topic in topics]
181
- # Call create_topics to asynchronously create topics, a dict
182
- # of <topic,future> is returned.
183
- fs = a.create_topics(new_topics)
184
-
185
- # Wait for each operation to finish.
186
- for topic, f in fs.items():
187
- try :
188
- f.result() # The result itself is None
189
- print (" Topic {} created" .format(topic))
190
- except Exception as e:
191
- print (" Failed to create topic {} : {} " .format(topic, e))
180
+ from confluent_kafka.admin import AdminClient, NewTopic
181
+
182
+ a = AdminClient({' bootstrap.servers' : ' mybroker' })
183
+
184
+ new_topics = [NewTopic(topic, num_partitions = 3 , replication_factor = 1 ) for topic in [" topic1" , " topic2" ]]
185
+ # Call create_topics to asynchronously create topics, a dict
186
+ # of <topic,future> is returned.
187
+ fs = a.create_topics(new_topics)
188
+
189
+ # Wait for each operation to finish.
190
+ for topic, f in fs.items():
191
+ try :
192
+ f.result() # The result itself is None
193
+ print (" Topic {} created" .format(topic))
194
+ except Exception as e:
195
+ print (" Failed to create topic {} : {} " .format(topic, e))
192
196
```
193
197
194
198
0 commit comments