I'm a newb to kafka and trying to create a simple hello world application using the link tutorial. I got the zookeeper running followed by the kafka-server-start command, but when I execute the producer I get the following error
Traceback (most recent call last):
File "D:/Python/consumer.py", line 1, in <module>
from kafka import KafkaConsumer
File "D:\Python\venv\lib\site-packages\kafka\__init__.py", line 23, in <module>
from kafka.producer import KafkaProducer
File "D:\Python\venv\lib\site-packages\kafka\producer\__init__.py", line 4, in <module>
from .simple import SimpleProducer
File "D:\Python\venv\lib\site-packages\kafka\producer\simple.py", line 54
return '<SimpleProducer batch=%s>' % self.async
^
SyntaxError: invalid syntax
I tried modifying the kafka-python version to 1.4.3, nothing seems to be working. Any pointers would be greatly appreciated Following are my python files: Producer.py:
from kafka import KafkaProducer
producer = KafkaProducer(bootstrap_servers='localhost:9092')
producer.send('sample', b'Hello, World!')
producer.send('sample', key=b'message-two', value=b'This is Kafka-Python')
Consumer.py:
from kafka import KafkaConsumer
consumer = KafkaConsumer('sample')
for message in consumer:
print (message)
The steps I followed are:
1. Initiate the zookeeper using the command
.\bin\windows\zookeeper-server-start.bat .\config\zookeeper.properties
2. After the zookeeper is initiated I executed the command
.\bin\windows\kafka-server-start.bat .\config\server.properties
3. When the server was initiated I ran the command python producer.py followed by consumer.py
Could someone tell me where am I going wrong? Thanks!