Startonix / Modular-AI

Advanced AI Training and Building Repository
0 stars 0 forks source link

Real-time Data Streaming with Apache Kafka #138

Open Startonix opened 5 months ago

Startonix commented 5 months ago

kafka_producer.py

from kafka import KafkaProducer

producer = KafkaProducer(bootstrap_servers='localhost:9092') producer.send('example_topic', b'some_message_bytes') producer.flush()

Startonix commented 5 months ago

kafka_consumer.py

from kafka import KafkaConsumer

consumer = KafkaConsumer('example_topic', bootstrap_servers='localhost:9092') for message in consumer: print(f"Received message: {message.value}")