我正在调用一个从 kafka 生产者发送一些数据的函数,但是在它发送之后我返回了一个不返回的响应。代码在返回时卡住了。有人知道发生了什么吗?
我的代码如下,
def postEvent(eventData):
print("The eventData is...",eventData)
timestamp = datetime.now().__format__("%Y-%m-%d %H:%M:%S")
try:
producer = KafkaProducer(bootstrap_servers=["host:port"])
data = json.dumps(eventData).encode('utf-8')
try:
kafkaResponse = producer.send('streamTest', data)
response ={'time': str(timestamp), 'kafkaResponse':kafkaResponse.get(),
'postResult': 'true'}
print('kafaka response is...', response)
except ConnectionAbortedError:
response ={'time': str(timestamp), 'postResult': 'false'}
except kafka.errors.KafkaTimeoutError:
response ={'time': str(timestamp), 'postResult': 'false'}
print('kafaka response is...', response)
return response
except kafka.errors.NoBrokersAvailable:
response = {'Response':'Kafka Errors... NoBrokersAvailable'}
print('kafaka response ', response)
return response