Skip to content

Commit 8b5684e

Browse files
committed
fix admin client example
1 parent 0b831f2 commit 8b5684e

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

README.md

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -177,18 +177,22 @@ c.close()
177177
Create topics:
178178

179179
```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))
192196
```
193197

194198

0 commit comments

Comments
 (0)