m2m模型翻译
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

34 lines
1.3 KiB

6 months ago
  1. from __future__ import absolute_import
  2. from kafka.errors import IllegalArgumentError
  3. class NewTopic(object):
  4. """ A class for new topic creation
  5. Arguments:
  6. name (string): name of the topic
  7. num_partitions (int): number of partitions
  8. or -1 if replica_assignment has been specified
  9. replication_factor (int): replication factor or -1 if
  10. replica assignment is specified
  11. replica_assignment (dict of int: [int]): A mapping containing
  12. partition id and replicas to assign to it.
  13. topic_configs (dict of str: str): A mapping of config key
  14. and value for the topic.
  15. """
  16. def __init__(
  17. self,
  18. name,
  19. num_partitions,
  20. replication_factor,
  21. replica_assignments=None,
  22. topic_configs=None,
  23. ):
  24. if not (num_partitions == -1 or replication_factor == -1) ^ (replica_assignments is None):
  25. raise IllegalArgumentError('either num_partitions/replication_factor or replica_assignment must be specified')
  26. self.name = name
  27. self.num_partitions = num_partitions
  28. self.replication_factor = replication_factor
  29. self.replica_assignments = replica_assignments or {}
  30. self.topic_configs = topic_configs or {}