diff options
author | Richard Lee <github@richardlee.name> | 2018-07-12 11:39:29 -0700 |
---|---|---|
committer | Jeff Widman <jeff@jeffwidman.com> | 2018-10-24 22:42:12 -0700 |
commit | 481f88068bdf0a18f12fd7a811b795f889d35fc7 (patch) | |
tree | 818f3b1ff92c847f90da3e9f2603d8100e899a50 /kafka/admin/new_topic.py | |
parent | ac9d5623116a5754c57a8ecd95b2954ba0f30c14 (diff) | |
download | kafka-python-481f88068bdf0a18f12fd7a811b795f889d35fc7.tar.gz |
Add KafkaAdmin class
Requires cluster version > 0.10.0.0, and uses new wire protocol
classes to do many things via broker connection that previously
needed to be done directly in zookeeper.
Diffstat (limited to 'kafka/admin/new_topic.py')
-rw-r--r-- | kafka/admin/new_topic.py | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/kafka/admin/new_topic.py b/kafka/admin/new_topic.py new file mode 100644 index 0000000..645ac38 --- /dev/null +++ b/kafka/admin/new_topic.py @@ -0,0 +1,34 @@ +from __future__ import absolute_import + +from kafka.errors import IllegalArgumentError + + +class NewTopic(object): + """ A class for new topic creation + Arguments: + name (string): name of the topic + num_partitions (int): number of partitions + or -1 if replica_assignment has been specified + replication_factor (int): replication factor or -1 if + replica assignment is specified + replica_assignment (dict of int: [int]): A mapping containing + partition id and replicas to assign to it. + topic_configs (dict of str: str): A mapping of config key + and value for the topic. + """ + + def __init__( + self, + name, + num_partitions, + replication_factor, + replica_assignments=None, + topic_configs=None, + ): + if not (num_partitions == -1 or replication_factor == -1) ^ (replica_assignments is None): + raise IllegalArgumentError('either num_partitions/replication_factor or replica_assignment must be specified') + self.name = name + self.num_partitions = num_partitions + self.replication_factor = replication_factor + self.replica_assignments = replica_assignments or {} + self.topic_configs = topic_configs or {} |