__init__.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. from __future__ import absolute_import
  2. __title__ = 'kafka'
  3. from .version import __version__
  4. __author__ = 'Dana Powers'
  5. __license__ = 'Apache License 2.0'
  6. __copyright__ = 'Copyright 2016 Dana Powers, David Arthur, and Contributors'
  7. # Set default logging handler to avoid "No handler found" warnings.
  8. import logging
  9. try: # Python 2.7+
  10. from logging import NullHandler
  11. except ImportError:
  12. class NullHandler(logging.Handler):
  13. def emit(self, record):
  14. pass
  15. logging.getLogger(__name__).addHandler(NullHandler())
  16. from kafka.consumer import KafkaConsumer
  17. from kafka.consumer.subscription_state import ConsumerRebalanceListener
  18. from kafka.producer import KafkaProducer
  19. from kafka.conn import BrokerConnection
  20. from kafka.protocol import (
  21. create_message, create_gzip_message, create_snappy_message)
  22. from kafka.partitioner import RoundRobinPartitioner, HashedPartitioner, Murmur2Partitioner
  23. from kafka.structs import TopicPartition, OffsetAndMetadata
  24. from kafka.serializer import Serializer, Deserializer
  25. # To be deprecated when KafkaProducer interface is released
  26. from kafka.client import SimpleClient
  27. from kafka.producer import SimpleProducer, KeyedProducer
  28. # deprecated in favor of KafkaConsumer
  29. from kafka.consumer import SimpleConsumer, MultiProcessConsumer
  30. import warnings
  31. class KafkaClient(SimpleClient):
  32. def __init__(self, *args, **kwargs):
  33. warnings.warn('The legacy KafkaClient interface has been moved to'
  34. ' kafka.SimpleClient - this import will break in a'
  35. ' future release', DeprecationWarning)
  36. super(KafkaClient, self).__init__(*args, **kwargs)
  37. __all__ = [
  38. 'KafkaConsumer', 'KafkaProducer', 'KafkaClient', 'BrokerConnection',
  39. 'SimpleClient', 'SimpleProducer', 'KeyedProducer',
  40. 'RoundRobinPartitioner', 'HashedPartitioner',
  41. 'create_message', 'create_gzip_message', 'create_snappy_message',
  42. 'SimpleConsumer', 'MultiProcessConsumer',
  43. ]