0
votes

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,

  1. Is it enough to install kafka-python using "pip install kafka-python" ? or should I need to download zookeeper and kafka seperately ?

  2. 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" ?

1
Did you start the services?Nishu Tayal
Do we need to install kafka seperately to start the service ?Mahesh babu

1 Answers

0
votes

I have not installed kafka

Not clear what you're expecting to produce/consume from, then

should I need to download zookeeper and kafka seperately

Yes. You need to install, configure and start the servers before running clients that connect to these services