88from itertools import cycle
99from multiprocessing import Queue , Process
1010
11- from kafka .common import ProduceRequest
11+ from kafka .common import ProduceRequest , TopicAndPartition
1212from kafka .partitioner import HashedPartitioner
1313from kafka .protocol import create_message
1414
@@ -44,25 +44,27 @@ def _send_upstream(queue, client, batch_time, batch_size,
4444 # timeout is reached
4545 while count > 0 and timeout >= 0 :
4646 try :
47- topic , partition , msg = queue .get (timeout = timeout )
47+ topic_partition , msg = queue .get (timeout = timeout )
4848
4949 except Empty :
5050 break
5151
5252 # Check if the controller has requested us to stop
53- if topic == STOP_ASYNC_PRODUCER :
53+ if topic_partition == STOP_ASYNC_PRODUCER :
5454 stop = True
5555 break
5656
5757 # Adjust the timeout to match the remaining period
5858 count -= 1
5959 timeout = send_at - time .time ()
60- msgset [( topic , partition ) ].append (msg )
60+ msgset [topic_partition ].append (msg )
6161
6262 # Send collected requests upstream
6363 reqs = []
64- for (topic , partition ), messages in msgset .items ():
65- req = ProduceRequest (topic , partition , messages )
64+ for topic_partition , messages in msgset .items ():
65+ req = ProduceRequest (topic_partition .topic ,
66+ topic_partition .partition ,
67+ messages )
6668 reqs .append (req )
6769
6870 try :
@@ -136,7 +138,8 @@ def send_messages(self, topic, partition, *msg):
136138 """
137139 if self .async :
138140 for m in msg :
139- self .queue .put ((topic , partition , create_message (m )))
141+ self .queue .put ((TopicAndPartition (topic , partition ),
142+ create_message (m )))
140143 resp = []
141144 else :
142145 messages = [create_message (m ) for m in msg ]
@@ -155,7 +158,7 @@ def stop(self, timeout=1):
155158 forcefully cleaning up.
156159 """
157160 if self .async :
158- self .queue .put ((STOP_ASYNC_PRODUCER , None , None ))
161+ self .queue .put ((STOP_ASYNC_PRODUCER , None ))
159162 self .proc .join (timeout )
160163
161164 if self .proc .is_alive ():
0 commit comments