Merge updates from PR 573 into README (serializer/deserializer examples)
This commit is contained in:
@@ -59,7 +59,7 @@ that expose basic message attributes: topic, partition, offset, key, and value:
|
|||||||
>>> msg = next(consumer)
|
>>> msg = next(consumer)
|
||||||
|
|
||||||
>>> # Deserialize msgpack-encoded values
|
>>> # Deserialize msgpack-encoded values
|
||||||
>>> consumer = KafkaConsumer(value_deserializer=msgpack.dumps)
|
>>> consumer = KafkaConsumer(value_deserializer=msgpack.loads)
|
||||||
>>> consumer.subscribe(['msgpackfoo'])
|
>>> consumer.subscribe(['msgpackfoo'])
|
||||||
>>> for msg in consumer:
|
>>> for msg in consumer:
|
||||||
... assert isinstance(msg.value, dict)
|
... assert isinstance(msg.value, dict)
|
||||||
@@ -89,7 +89,7 @@ for more details.
|
|||||||
|
|
||||||
>>> # Serialize json messages
|
>>> # Serialize json messages
|
||||||
>>> import json
|
>>> import json
|
||||||
>>> producer = KafkaProducer(value_serializer=json.loads)
|
>>> producer = KafkaProducer(value_serializer=lambda v: json.dumps(v).encode('utf-8'))
|
||||||
>>> producer.send('fizzbuzz', {'foo': 'bar'})
|
>>> producer.send('fizzbuzz', {'foo': 'bar'})
|
||||||
|
|
||||||
>>> # Serialize string keys
|
>>> # Serialize string keys
|
||||||
|
|||||||
Reference in New Issue
Block a user