I'm calling a function which sends some data from kafka producer, but after it sends I'm returning a response which doesn't return. The code gets stuck at return. Anyone any idea whats happening?
My code is as follows,
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