Producer in Python
Phew ! Congrats on arriving to this section. We will learn how to create a Producer and write to your Kafka Cluster.
Last updated
Phew ! Congrats on arriving to this section. We will learn how to create a Producer and write to your Kafka Cluster.
Last updated
"Python client for the Apache Kafka distributed stream processing system. kafka-python is designed to function much like the official java client, with a sprinkling of pythonic interfaces (e.g., consumer iterators)."
Checkout the documentation for creating a Kafka Producer
Once you've read enough :) go to the producer.py
file and create a producer under produce_messages
method
Sending messages to kafka it could be as simple as Sending Strings :) This code will show you how to send it to a topic called twitter-handlers
In real life, the probability of sending single strings to a topic is barely true. Reality is companies and projects are loaded with heavily complex data structures and schemas to be processed by services and applications.
We will work with the following schema:
The schema provided will help us to serialize the data into avro format.
We are going to run through the Avro code quickly before heading off to sending our messages:
The code above is not completed :) We have just created each avro message. Could you guess what else is needed ?
Try yourself to send the messages.
In order to check if you are correctly sending the messages use the kafka-console-producer
previously seen or wait until next section :-P
Good practice: Do not forget to close your producer once you are done.
Checkout