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.

27 lines
906 B

6 months ago
  1. from __future__ import absolute_import
  2. class Partitioner(object):
  3. """
  4. Base class for a partitioner
  5. """
  6. def __init__(self, partitions=None):
  7. """
  8. Initialize the partitioner
  9. Arguments:
  10. partitions: A list of available partitions (during startup) OPTIONAL.
  11. """
  12. self.partitions = partitions
  13. def __call__(self, key, all_partitions=None, available_partitions=None):
  14. """
  15. Takes a string key, num_partitions and available_partitions as argument and returns
  16. a partition to be used for the message
  17. Arguments:
  18. key: the key to use for partitioning.
  19. all_partitions: a list of the topic's partitions.
  20. available_partitions: a list of the broker's currently avaliable partitions(optional).
  21. """
  22. raise NotImplementedError('partition function has to be implemented')