from kafka import KafkaProducer producer = KafkaProducer(bootstrap_servers='localhost:9092', bootstrap_connected=True) producer.send('test-topic', b'Hello, world!')
from kafka import KafkaProducer producer = KafkaProducer(bootstrap_servers='localhost:9092', bootstrap_connected=False) producer.send('test-topic', b'Hello, world!')This code creates a KafkaProducer instance with the bootstrap server's address but does not connect to it initially. Then it sends a message to the 'test-topic' topic, and the client connects to the broker specified in the bootstrap_servers parameter. Package Library: kafka-python In both examples, the send() method sends a message to the specified Kafka topic. The first parameter to the send() method is the name of the Kafka topic, and the second parameter is the message payload in bytes.