summaryrefslogtreecommitdiff
path: root/README.md
diff options
context:
space:
mode:
authorDana Powers <dana.powers@rd.io>2014-08-26 13:15:25 -0700
committerDana Powers <dana.powers@rd.io>2014-08-26 16:59:46 -0700
commita28120aa8bedc24540cd6269435b71c272b55386 (patch)
treefc3369bd0c4c0251b3b371b0e3936f1a8a65234d /README.md
parentf7be23f6a761fd85a22437b67fdab61303bfc9e0 (diff)
downloadkafka-python-a28120aa8bedc24540cd6269435b71c272b55386.tar.gz
Raise TypeError in kafka.producer.send_messages if any msg is not a str (or subclass); document
Diffstat (limited to 'README.md')
-rw-r--r--README.md7
1 files changed, 7 insertions, 0 deletions
diff --git a/README.md b/README.md
index f123435..e176bad 100644
--- a/README.md
+++ b/README.md
@@ -42,9 +42,14 @@ kafka = KafkaClient("localhost:9092")
# To send messages synchronously
producer = SimpleProducer(kafka)
+
+# Note that the application is responsible for encoding messages to type str
producer.send_messages("my-topic", "some message")
producer.send_messages("my-topic", "this method", "is variadic")
+# Send unicode message
+producer.send_messages("my-topic", u'你怎么样?'.encode('utf-8'))
+
# To send messages asynchronously
producer = SimpleProducer(kafka, async=True)
producer.send_messages("my-topic", "async message")
@@ -78,6 +83,8 @@ producer = SimpleProducer(kafka, batch_send=True,
# To consume messages
consumer = SimpleConsumer(kafka, "my-group", "my-topic")
for message in consumer:
+ # message is raw byte string -- decode if necessary!
+ # e.g., for unicode: `message.decode('utf-8')`
print(message)
kafka.close()