Open Startonix opened 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()
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}")
kafka_producer.py
from kafka import KafkaProducer
producer = KafkaProducer(bootstrap_servers='localhost:9092') producer.send('example_topic', b'some_message_bytes') producer.flush()