<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Siddhi Agrawal on Medium]]></title>
        <description><![CDATA[Stories by Siddhi Agrawal on Medium]]></description>
        <link>https://medium.com/@siddhiagr3008?source=rss-822cc54ad743------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*hZzHTW87_9KnoM-VYCBARw.jpeg</url>
            <title>Stories by Siddhi Agrawal on Medium</title>
            <link>https://medium.com/@siddhiagr3008?source=rss-822cc54ad743------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 20:18:07 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@siddhiagr3008/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Kafka Basics with Kafka-Python]]></title>
            <link>https://medium.com/@siddhiagr3008/kafka-basics-with-kafka-python-1514d9b05062?source=rss-822cc54ad743------2</link>
            <guid isPermaLink="false">https://medium.com/p/1514d9b05062</guid>
            <dc:creator><![CDATA[Siddhi Agrawal]]></dc:creator>
            <pubDate>Mon, 15 Jan 2024 20:41:22 GMT</pubDate>
            <atom:updated>2024-01-16T04:55:05.005Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/938/1*F0Q_gWQECE5SZ3dQJdzmIQ.jpeg" /></figure><p>In this article, we will look into the fundamental concepts of Kafka, exploring its core components and terminologies. I will be focusing on understanding these concepts in the context of Python, using the kafka-python library.</p><p>Apache Kafka is an open-source distributed system consisting of servers and clients. Apache Kafka is used primarily to build real-time data streaming pipelines. It’s like a post office, where you can send or receive messages (data) in real time. Kafka Python is a Python client for Apache Kafka. It’s like a postman who can deliver or pick up your mail (data) from the post office (Kafka).</p><p>For knowing about kafka you should be knowing about these main terminologies :</p><ol><li><strong>Topics : </strong>It’s like a channel where messages are sent. Each message in Kafka is tagged with a topic name, helping organize information.</li><li><strong>Partitions </strong>: Partitions are like lanes on a highway. They help Kafka handle lots of messages by dividing them into sections. If you have a “Weather” topic with three partitions, it’s like having three lanes to handle different weather updates. This helps Kafka work faster and smoother.</li><li><strong>Replication factor :</strong> Imagine you have a backup friend who knows everything you know. The replication factor in Kafka is similar. It decides how many copies of your messages (or partitions) are kept. If you set a replication factor of 2, Kafka makes sure there are two copies of each message. So, even if one “friend” (or server) is not available, the other can still help out.</li><li><strong>Producer :</strong> The producer is like a news reporter who sends updates to a topic. For instance, a weather sensor is a producer that shares temperature news with the “Weather” topic. Producers make sure the information gets into Kafka for others to read.</li><li><strong>Consumer :</strong> Consumers are like people who subscribe to newspapers. They read messages from topics. Imagine a weather app on your phone. It’s a consumer that subscribes to the “Weather” topic, showing you the latest updates sent by the producer.</li><li><strong>Broker :</strong> A broker is a Kafka server that stores data, receives messages from producers, and serves messages to consumers. It’s like a post office handling messages. In a Kafka cluster, there are multiple brokers, and they work together to manage the storage and retrieval of messages. If you have a Kafka cluster with three brokers, each handling a portion of the data, it enhances the system’s performance.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0_fTcH-Ngx8IV1DzViHeqQ.jpeg" /></figure><h3><strong>Installation of Kafka Python library</strong></h3><p>Firstly, we need to set up the Apache Kafka Environment. To do this follow this steps :-</p><p><strong>Step 1 — Installing Java</strong></p><p>If you have Java installed on your system then only you can run Apache Kafka. In order to setup the kafka we need to install java first. If Java is not downloaded, please download the latest version of JDK by visiting the following link and download latest version.</p><p><a href="https://www.oracle.com/java/technologies/downloads/#jdk21-mac">https://www.oracle.com/java/technologies/downloads/#jdk21-mac</a></p><p>The latest version is JDK 21 and the file is x64 Compressed Archive. Extract the tar file.</p><p><strong>Step 2— Apache Kafka Installation</strong></p><p>Download the latest version of Apache kafka binary files from it’s offical <a href="https://kafka.apache.org/downloads">website</a> and extract the tar file.</p><pre>$ tar -xzf kafka_2.13-3.6.1.tgz<br>$ cd kafka_2.13-3.6.1</pre><p><strong>Step 3— Zookeeper Installation</strong></p><p>Run the following commands in order to start zookeeper service. After you start the zookeeper then only you can start Kafka.</p><pre>$ bin/zookeeper-server-start.sh config/zookeeper.properties</pre><p>Now start the kafka in the another terminal.</p><pre>bin/kafka-server-start.sh config/server.properties</pre><p><strong>Step 4— Topic Creation in Kafka</strong></p><p>We can create n number of topics on the serverby using the following command. I have set the topic name as “Hello”, you can change as per your choice.</p><pre>bin/kafka-topics.sh --bootstrap-server localhost:9092 --create --topic Hello</pre><p>If you want intialize partitions and replication factor , we can do it by the following command. In the example, i have set partitions to 3 and replication factor as 1.</p><pre>bin/kafka-topics.sh --bootstrap-server localhost:9092 --create --topic Hello --partitons 3 --replication-factor 1</pre><p>To list down all the topics we have created use this command.</p><pre>bin/kafka-topics.sh --bootstrap-server localhost:9092 --list</pre><p><strong>Step 5— Start Producer to Send Messages to the Broker</strong></p><p>kafka-console-producer.sh, initiates a tool to send messages to a Kafka messaging system. It connects to a specified Kafka broker using the --bootstrap-server parameter and designates a target topic using the --topic parameter. Once activated, you can input messages directly into the console, and the producer will transmit them to the specified topic on the Kafka broker.</p><pre>bin/kafka-console-producer.sh --topic Hello --bootstrap-server localhost:9092</pre><p><strong>Step 6 — Start Consumer to Receive Messages</strong></p><p>Open a new teriminal and run the below command forvconsuming the messages.</p><pre>bin/kafka-console-consumer.sh --topic Hello --from-beginning --bootstrap-server localhost:9092</pre><p>To stop the execution in any of the terminals, you can use ctrl + c.</p><p>Hope this helps!!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1514d9b05062" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>