![]() To produce or consume lz4 compressed messages, you must install lz4tools and xxhash (modules may not work on python2.6). ![]() Kafka-python supports gzip compression/decompression natively. > producer = KafkaProducer(compression_type='gzip') > producer = KafkaProducer(key_serializer=str.encode) > producer = KafkaProducer(value_serializer=lambda v: json.dumps(v).encode('utf-8')) > nd('foobar', b'another_message').get(timeout=60) > # Block until a single message is sent (or timeout) > # Block until all pending messages are sent > producer = KafkaProducer(bootstrap_servers='localhost:1234') The class is intended to operate as similarly as possible to the official java client. KafkaProducer is a high-level, asynchronous message producer. > consumer = KafkaConsumer(value_deserializer=msgpack.loads) > consumer = KafkaConsumer(bootstrap_servers='localhost:1234') > # manually assign the partition list for the consumer ![]() > consumer = KafkaConsumer('my_favorite_topic') The consumer iterator returns ConsumerRecords, which are simple namedtuples that expose basic message attributes: topic, partition, offset, key, and value: > from kafka import KafkaConsumer Full support for coordinated consumer groups requires use of kafka brokers that support the Group APIs: kafka v0.9+. KafkaConsumer is a high-level message consumer, intended to operate as similarly as possible to the official java client. For release documentation, please see readthedocs and/or python's inline help. Please note that the master branch may contain unreleased features. This approach will work fine, though it does not support rebalancing on failures. For older brokers, you can achieve something similar by manually assigning different partitions to each consumer instance with config management tools like chef, ansible, etc. Supporting this feature for earlier broker releases would require writing and maintaining custom leadership election and membership / health check code (perhaps using zookeeper or consul). Some features will only be enabled on newer brokers, however for example, fully coordinated consumer groups - i.e., dynamic partition assignment to multiple consumers in the same group - requires use of 0.9+ kafka brokers. Kafka-python is best used with newer brokers (0.10 or 0.9), but is backwards-compatible with older versions (to 0.8.0).
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |