I am trying to read messages from Azure Event Hub using kafka API. But I am unable to connect to the event hub. The bootstrap_connected() function always return false and the code stops there. It is not going to print message part. Below is my code
from kafka import KafkaConsumer
from json import loads
consumer = KafkaConsumer(<EVENTHUB_NAME>,
bootstrap_servers='<NAME>.servicebus.windows.net:9093',
auto_offset_reset='earliest',
enable_auto_commit=True,
security_protocol='SASL_SSL',
sasl_mechanism='PLAIN',
sasl_plain_username=<CLIENT ID>,
sasl_plain_password=<CONNECTION_STRING>,
group_id=<CONSUMER_GROUP_NAME>,
api_version=(0, 11),
value_deserializer=lambda x: loads(x.decode('utf-8')))
print(consumer) #returns <kafka.consumer.group.KafkaConsumer object at 0x00000000012A8130>
x = consumer.bootstrap_connected() #returns False
print(x)
for message in consumer:
message = message.value
print('{} added'.format(message))
I have followed the documentation but not sure why it is not connecting. I am able to use Azure's EventHubConsumerClient and able to receive the message. But my business logic requires to use Kafka Consumer Client. Please do help me in finding a solution for this!