I want to produce and consume kafka topic through a simple python script. As explained in: https://towardsdatascience.com/getting-started-with-apache-kafka-in-python-604b3250aa05 I have created publish_message and connect_kafka_producer using bootstrap_servers=['localhost:9092'] and produced a simple "Hello message" as below:
kafka_producer = connect_kafka_producer()
publish_message(kafka_producer, 'Hello_topic', 'Hello', "Hello")
When I try to run this python function, I see below errors:
DEBUG:kafka.metrics.metrics:Added sensor with name node-bootstrap-0.latency
DEBUG:kafka.conn:<BrokerConnection node_id=bootstrap-0 host=localhost:9092 [unspecified None]>: creating new socket
DEBUG:kafka.conn:<BrokerConnection node_id=bootstrap-0 host=localhost:9092 [IPv4 ('127.0.0.1', 9092)]>: setting socket option (6, 1, 1)
INFO:kafka.conn:<BrokerConnection node_id=bootstrap-0 host=localhost:9092 [IPv4 ('127.0.0.1', 9092)]>: connecting to localhost:9092 [('127.0.0.1', 9092) IPv4]
ERROR:kafka.conn:Connect attempt to <BrokerConnection node_id=bootstrap-0 host=localhost:9092 [IPv4 ('127.0.0.1', 9092)]> returned error 111. Disconnecting.
INFO:kafka.conn:<BrokerConnection node_id=bootstrap-0 host=localhost:9092 [IPv4 ('127.0.0.1', 9092)]>: Closing connection. KafkaConnectionError: 111 ECONNREFUSED
DEBUG:kafka.conn:<BrokerConnection node_id=bootstrap-0 host=localhost:9092 [IPv4 ('127.0.0.1', 9092)]>: reconnect backoff 0.04205048432501722 after 1 failures
DEBUG:kafka.client:Give up sending metadata request since no node is available
My question is,
Is it enough to install kafka-python using "pip install kafka-python" ? or should I need to download zookeeper and kafka seperately ?
As mentioned in https://www.confluent.io/blog/kafka-client-cannot-connect-to-broker-on-aws-on-docker-etc/, I can not see server.properties file to change advertised.listeners to localhost:9092, is this because I have not installed kafka and I am only using "pip install kafka-python" ?