I'm searching for a solution to use Kafka to display my API (localhost) to my docker.
My producer file works fine and here it is
Consumer file on the other hand returns this... I tried creating a new test container in powershell to debug, gave me nobrokersavailable
Producer:
from kafka import KafkaProducer
import json
producer = KafkaProducer(bootstrap_servers='localhost:9092',
value_serializer=lambda v: json.dumps(v).encode('utf-8'))
with open('data/New York_0.json', 'r') as f:
data = json.load(f)
producer.send('my_topic', data)
producer.flush()
Consumer:
from kafka import KafkaConsumer
import json
import traceback
# To consume latest messages and auto-commit offsets
try:
consumer = KafkaConsumer('my_topic',
bootstrap_servers='localhost:9092',
value_deserializer=lambda m: json.loads(m.decode('utf-8')),
consumer_timeout_ms=6000,
enable_auto_commit=False)
print("Consumer created, start consuming")
for message in consumer:
print(message.value)
except Exception as e:
print(f"An error occurred: {e}")
print(f"Exception Type: {type(e).__name__}")
traceback.print_exc()
finally:
print("Closing the consumer")
consumer.close()
Created test container to run a test_producer.py file, gave me nobrokersavailable
disabled firewall when this happened, same thing