@@ -148,7 +148,28 @@ def __init__(self, client, async=False,
148
148
def send_messages (self , topic , partition , * msg ):
149
149
"""
150
150
Helper method to send produce requests
151
+ @param: topic, name of topic for produce request -- type str
152
+ @param: partition, partition number for produce request -- type int
153
+ @param: *msg, one or more message payloads -- type str
154
+ @returns: ResponseRequest returned by server
155
+ raises on error
156
+
157
+ Note that msg type *must* be encoded to str by user.
158
+ Passing unicode message will not work, for example
159
+ you should encode before calling send_messages via
160
+ something like `unicode_message.encode('utf-8')`
161
+
162
+ All messages produced via this method will set the message 'key' to Null
151
163
"""
164
+
165
+ # Guarantee that msg is actually a list or tuple (should always be true)
166
+ if not isinstance (msg , (list , tuple )):
167
+ raise TypeError ("msg is not a list or tuple!" )
168
+
169
+ # Raise TypeError if any message is not encoded as a str
170
+ if any (not isinstance (m , str ) for m in msg ):
171
+ raise TypeError ("all produce message payloads must be type str" )
172
+
152
173
if self .async :
153
174
for m in msg :
154
175
self .queue .put ((TopicAndPartition (topic , partition ), m ))
0 commit comments