Complete the code to create a Kafka producer.
from kafka import KafkaProducer producer = KafkaProducer(bootstrap_servers=[1])
The Kafka producer connects to the Kafka broker using the bootstrap server address, usually 'localhost:9092'.
Complete the code to send a message to a Kafka topic.
producer.send([1], b'Hello Kafka')
The send method requires the topic name as a string to send messages.
Fix the error in the code to properly flush the Kafka producer.
producer.[1]()The flush() method ensures all buffered messages are sent to Kafka before continuing.
Fill both blanks to create a Kafka consumer that subscribes to a topic.
from kafka import KafkaConsumer consumer = KafkaConsumer([1], bootstrap_servers=[2])
The KafkaConsumer needs the topic name and the Kafka broker address to subscribe and consume messages.
Fill all three blanks to create a Kafka producer that sends a message and flushes it.
producer = KafkaProducer(bootstrap_servers=[1]) producer.send([2], b'Hello') producer.[3]()
This code creates a producer connected to the Kafka broker, sends a message to 'test_topic', and flushes the producer to ensure delivery.